Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- typedef long double ld;
- #define int long long
- const int c = 330;
- unordered_map<int, int> bl[c];
- int modify[c] = {};
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, q;
- cin >> n >> q;
- vector<int> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- bl[i / c][a[i]] += 1;
- }
- auto query = [&](int l, int r, int x) {
- bool ok = 0;
- for (int i = l; i <= r; ) {
- if (i % c == 0 && i + c - 1 <= r) {
- ok |= (bl[i / c].find(x - modify[i / c]) != bl[i / c].end());
- i += c;
- }
- else {
- ok |= (a[i] == (x - modify[i / c]));
- ++i;
- }
- }
- return ok;
- };
- auto upd = [&](int l, int r, int to) {
- for (int i = l; i <= r; ) {
- if (i % c == 0 && i + c - 1 <= r) {
- modify[i / c] += to;
- i += c;
- }
- else {
- bl[i / c][a[i]]--;
- if (bl[i / c][a[i]] == 0) {
- bl[i / c].erase(a[i]);
- }
- a[i] += to;
- bl[i / c][a[i]]++;
- ++i;
- }
- }
- };
- while (q--) {
- char tp;
- cin >> tp;
- if (tp == '?') {
- int l, r, x;
- cin >> l >> r >> x;
- l--, r--;
- bool ans = query(l, r, x);
- cout << (ans ? "YES" : "NO") << '\n';
- }
- if (tp == '+') {
- int l, r, x;
- cin >> l >> r >> x;
- l--, r--;
- upd(l, r, x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement