Advertisement
ssrtatarin

Untitled

Jul 9th, 2025
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define int long long
  5. const int inf = 1e9;
  6.  
  7. ll M2 = 1e9 + 9, M1 = 1e9 + 7;
  8. //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  9.  
  10. void solve() {
  11.     int n;
  12.     cin >> n;
  13.     vector<vector<int>> g(n + 1);
  14.     vector<int> a(n);
  15.     map<int, int> maps;
  16.     for (auto &i : a) {
  17.         cin >> i;
  18.         maps[i] += 1;
  19.     }
  20.     int num = 1;
  21.     for (auto &[i, j] : maps) {
  22.         j = num;
  23.         num += 1;
  24.     }
  25.     for (auto &i : a) i = maps[i];
  26.     for (int i = 0; i < n; ++i) {
  27.         g[a[i]].push_back(i);
  28.     }
  29.     int q;
  30.     cin >> q;
  31.     while (q--) {
  32.         int l, r, x;
  33.         cin >> l >> r >> x;
  34.         --l, --r;
  35.         if (maps[x] == 0) {
  36.             cout << "0";
  37.             continue;
  38.         }
  39.         int res = upper_bound(g[maps[x]].begin(), g[maps[x]].end(), r) - lower_bound(g[maps[x]].begin(), g[maps[x]].end(), l);
  40.        
  41.         cout << (res <= 0 ? 0 : 1);
  42.     }
  43.  
  44.  
  45.  
  46. }
  47.  
  48. signed main() {
  49.  
  50.  
  51.     ios_base::sync_with_stdio(false);
  52.     cin.tie(nullptr);
  53.     ll thrush = 1;
  54.     //cin >> thrush;
  55.     while (thrush--) { solve();}
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement