fork download
  1. /*
  2. * @Author: hungeazy
  3. * @Date: 2026-03-04 23:24:15
  4. * @Last Modified by: hungeazy
  5. * @Last Modified time: 2026-03-13 21:11:37
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #define int long long
  10. const int N = 100010;
  11. int n,q,a[N];
  12. vector<int> pos[N];
  13.  
  14. signed main()
  15. {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(NULL); cout.tie(NULL);
  18. cin >> n >> q;
  19. for (int i = 1; i <= n; i++)
  20. {
  21. cin >> a[i];
  22. pos[a[i]].push_back(i);
  23. }
  24. for (int i = 1; i <= q; i++)
  25. {
  26. int l,r,x;
  27. cin >> l >> r >> x;
  28. int L = 0, R = pos[x].size()-1, jMin = -1, jMax = -1;
  29. while (L <= R)
  30. {
  31. int mid = (L+R)>>1;
  32. if (pos[x][mid] >= l)
  33. {
  34. jMin = mid;
  35. R = mid-1;
  36. }
  37. else L = mid+1;
  38. }
  39. L = 0, R = pos[x].size()-1;
  40. while (L <= R)
  41. {
  42. int mid = (L+R)>>1;
  43. if (pos[x][mid] <= r)
  44. {
  45. jMax = mid;
  46. L = mid+1;
  47. }
  48. else R = mid-1;
  49. }
  50. if (jMin != -1 and jMax != -1) cout << jMax-jMin+1 << endl;
  51. else cout << 0 << endl;
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 6268KB
stdin
Standard input is empty
stdout
Standard output is empty