Advertisement
ivnikkk

Untitled

Aug 9th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "bits/stdc++.h"
  3. using namespace std;
  4. #define all(a) a.begin(), a.end()
  5. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  6. typedef long double ld;
  7. #define int long long
  8. const int c = 330;
  9. unordered_map<int, int> bl[c];
  10. int modify[c] = {};
  11. signed main() {
  12.     #ifdef _DEBUG
  13.         freopen("input.txt", "r", stdin);
  14.         freopen("output.txt", "w", stdout);
  15.     #endif
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(nullptr);
  18.     cout.tie(nullptr);
  19.     int n, q;
  20.     cin >> n >> q;
  21.     vector<int> a(n);
  22.     for (int i = 0; i < n; i++) {
  23.         cin >> a[i];
  24.         bl[i / c][a[i]] += 1;
  25.     }
  26.     auto query = [&](int l, int r, int x) {
  27.         bool ok = 0;
  28.         for (int i = l; i <= r; ) {
  29.             if (i % c == 0 && i + c - 1 <= r) {
  30.                 ok |= (bl[i / c].find(x - modify[i / c]) != bl[i / c].end());
  31.                 i += c;
  32.             }
  33.             else {
  34.                 ok |= (a[i] == (x - modify[i / c]));
  35.                 ++i;
  36.             }
  37.         }
  38.         return ok;
  39.     };
  40.     auto upd = [&](int l, int r, int to) {
  41.         for (int i = l; i <= r; ) {
  42.             if (i % c == 0 && i + c - 1 <= r) {
  43.                 modify[i / c] += to;
  44.                 i += c;
  45.             }
  46.             else {
  47.                 bl[i / c][a[i]]--;
  48.                 if (bl[i / c][a[i]] == 0) {
  49.                     bl[i / c].erase(a[i]);
  50.                 }
  51.                 a[i] += to;
  52.                 bl[i / c][a[i]]++;
  53.                 ++i;
  54.             }
  55.         }
  56.     };
  57.     while (q--) {
  58.         char tp;
  59.         cin >> tp;
  60.         if (tp == '?') {
  61.             int l, r, x;
  62.             cin >> l >> r >> x;
  63.             l--, r--;
  64.             bool ans = query(l, r, x);
  65.             cout << (ans ? "YES" : "NO") << '\n';
  66.         }
  67.         if (tp == '+') {
  68.             int l, r, x;
  69.             cin >> l >> r >> x;
  70.             l--, r--;
  71.             upd(l, r, x);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement