fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define el cout << '\n'
  5.  
  6. using namespace std;
  7.  
  8. struct Query
  9. {
  10. int id, x, mobius;
  11. };
  12.  
  13. const int maxn = 1e6;
  14. const int maxx = 1e6;
  15.  
  16. int n, q, a[maxn + 10], cnt[maxx + 10], ans[maxn + 10];
  17. vector<Query> v[maxn + 10];
  18.  
  19. int main()
  20. {
  21. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  22. if (fopen("CNTX.INP", "r"))
  23. {
  24. freopen("CNTX.INP", "r", stdin);
  25. freopen("CNTX.OUT", "w", stdout);
  26. }
  27.  
  28. cin >> n;
  29. for (int i = 1; i <= n; i++)
  30. cin >> a[i];
  31. cin >> q;
  32. for (int i = 1; i <= q; i++)
  33. {
  34. int l, r, x;
  35. cin >> l >> r >> x;
  36. v[l - 1].push_back({i, x, -1});
  37. v[r].push_back({i, x, 1});
  38. }
  39. for (int i = 1; i <= n; i++)
  40. {
  41. cnt[a[i]]++;
  42. for (Query x : v[i])
  43. ans[x.id] += cnt[x.x] * x.mobius;
  44. }
  45. for (int i = 1; i <= q; i++)
  46. cout << ans[i], el;
  47. }
Success #stdin #stdout 0.01s 28892KB
stdin
Standard input is empty
stdout
Standard output is empty