fork download
  1. /// Author : Nguyễn Thái Sơn - K18 - KHMT - UIT
  2. /// Training ICPC 2024
  3.  
  4. #include<bits/stdc++.h>
  5.  
  6. /// #pragma GCC optimize("O3,unroll-loops")
  7. /// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  8.  
  9. #define fi first
  10. #define se second
  11. #define TASK "test"
  12. #define pb push_back
  13. #define EL cout << endl
  14. #define Ti20_ntson int main()
  15. #define in(x) cout << x << endl
  16. #define all(x) (x).begin(),(x).end()
  17. #define getbit(x, i) (((x) >> (i)) & 1)
  18. #define cntbit(x) __builtin_popcount(x)
  19. #define FOR(i,l,r) for (int i = l; i <= r; i++)
  20. #define FORD(i,l,r) for (int i = l; i >= r; i--)
  21. #define Debug(a,n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl
  22.  
  23. using namespace std;
  24.  
  25. typedef long long ll;
  26. typedef vector<int> vi;
  27. typedef pair<int,int> vii;
  28. typedef unsigned long long ull;
  29. typedef vector<vector<int>> vvi;
  30. int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
  31.  
  32. const int N = 2e5 + 5;
  33. const int oo = INT_MAX;
  34. const int mod = 1e9 + 7;
  35. const int d4x[4] = {-1, 0, 1, 0} , d4y[4] = {0, 1, 0, -1};
  36. const int d8x[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  37. const int BL = 447;
  38.  
  39. int n, a[N], cnt[N], Ans[N], Q;
  40.  
  41. struct Mo {
  42. int l, r, x, stt;
  43.  
  44. bool operator < (const Mo &T) const {
  45.  
  46. if (l / BL != T.l / BL)
  47. return l < T.l;
  48.  
  49. return r < T.r;
  50.  
  51. }
  52.  
  53. }t[N];
  54.  
  55. inline void Read_Input() {
  56. cin >> n;
  57. FOR(i, 1, n)
  58. cin >> a[i];
  59. cin >> Q;
  60. FOR(i, 1, Q) {
  61. cin >> t[i].l >> t[i].r >> t[i].x;
  62. t[i].stt = i;
  63. }
  64. sort(t + 1, t + Q + 1);
  65. }
  66.  
  67. inline void Solve() {
  68. int ctL = 0;
  69. int ctR = 1;
  70.  
  71. /// để hiểu ràng tôi đang có mảng [ctL, ctR - 1] = [0, 0]
  72.  
  73. FOR(i, 1, Q) {
  74.  
  75. int l = t[i].l;
  76. int r = t[i].r;
  77. int x = t[i].x;
  78. int stt = t[i].stt;
  79.  
  80. while (ctL < l) --cnt[a[ctL]], ctL++;
  81.  
  82. while (ctL > l) ctL--,++cnt[a[ctL]];
  83.  
  84. while (ctR - 1 > r) --ctR, --cnt[a[ctR]];
  85.  
  86. while (ctR <= r) ++cnt[a[ctR]], ctR++;
  87.  
  88. Ans[stt] = cnt[x];
  89.  
  90. }
  91.  
  92. FOR(i, 1, Q)
  93. cout << Ans[i] << endl;
  94.  
  95. }
  96.  
  97. Ti20_ntson {
  98. // freopen(TASK".INP","r",stdin);
  99. // freopen(TASK".OUT","w",stdout);
  100. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  101. int T = 1;
  102. // cin >> T;
  103. while (T -- ) {
  104. Read_Input();
  105. Solve();
  106. }
  107. }
  108.  
  109.  
  110.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty