fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define ld long double
  7. #define eb emplace_back
  8. #define pb push_back
  9. #define fi first
  10. #define se second
  11. #define nn '\n'
  12. #define pi pair<int, int>
  13. #define unmp unordered_map
  14. #define uns unordered_set
  15. #define lb lower_bound
  16. #define ub upper_bound
  17. #define pq priority_queue
  18. #define TASK " "
  19.  
  20. const int INF = 1e18;
  21. const int mod = 1e9+7;
  22. const int N = 5*1e5 + 5;
  23. int MOD = 998244353;
  24. int bit[200000];
  25. int n, q;
  26. map<int, vector<int>> mp;
  27. signed main(){
  28. ios_base::sync_with_stdio(0);
  29. cin.tie(0);
  30. cout.tie(0);
  31. cin >> n >> q;
  32. for(int i = 1; i <= n; i++){
  33. int x; cin >> x;
  34. mp[x].pb(i);
  35. }
  36. while(q--){
  37. int l, r, x;
  38. cin >> l >> r >> x;
  39. auto it = mp.find(x);
  40. if(it == mp.end()){
  41. cout << 0 << nn;
  42. continue;
  43. }
  44.  
  45. auto &vt = it->se;
  46. auto it1 = lb(vt.begin(), vt.end(), l);
  47. auto it2 = ub(vt.begin(), vt.end(), r);
  48. // int id1 = it1 - vt.begin();
  49. // int id2 = it2 - vt.begin();
  50. // cout << id1 << " " << id2 << nn;
  51. cout << it2 - it1 << nn;
  52. }
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 5280KB
stdin
8 1
1 1 2 3 1 2 3 2
2 5 1
stdout
2