Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- const int N = 1e5+7;
- int blockLen;
- int arr[N];
- struct Block {
- int real[101], sorted[101], real_s;
- int delta;
- Block() {
- delta = 0;
- real_s = 0;
- }
- void addtoReal(int l, int r, int x) {
- for (int i = 0; i < real_s; i++) {
- if (i >= l && i <= r) {
- real[i] += x;
- }
- real[i] += delta;
- sorted[i] = real[i];
- }
- delta = 0;
- sort(sorted, sorted + real_s);
- }
- void add(int x) {
- delta += x;
- }
- bool contains(int x) {
- int L = 0;
- int R = real_s - 1;
- while (R - L > 1) {
- int mid = (R + L) / 2;
- if (sorted[mid] + delta == x) {
- return 1;
- }
- if (sorted[mid] + delta < x) {
- L = mid;
- }
- else {
- R = mid;
- }
- }
- if (sorted[L] + delta == x || sorted[R] + delta == x) {
- return 1;
- }
- else {
- return 0;
- }
- }
- bool contains_stupid(int l, int r, int x) {
- for (int i = l; i <= r; i++) {
- if (real[i] + delta == x) {
- return 1;
- }
- }
- return 0;
- }
- };
- int n, bl_s, m, l,r,x,L,R;
- Block blocks[1003];
- int blocks_s = 0;
- char type;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> n >> m;
- bl_s = 100;
- Block bl;
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- if ((i % bl_s == 0 && i != 0)){
- sort(bl.sorted, bl.sorted + bl.real_s);
- blocks[blocks_s] = (bl);
- blocks_s++;
- bl.real_s = 1;
- bl.real[0] = (arr[i]);
- bl.sorted[0] = (arr[i]);
- }
- else {
- bl.real[bl.real_s] = (arr[i]);
- bl.sorted[bl.real_s] = (arr[i]);
- bl.real_s++;
- }
- }
- sort(bl.sorted, bl.sorted+bl.real_s);
- blocks[blocks_s] = (bl);
- blocks_s++;
- for (int I = 0; I < m; I++) {
- cin >> type >> l >> r >> x;
- l--;
- r--;
- if (type == '+') {
- L = (l / bl_s) * bl_s;
- R = L + blocks[l/bl_s].real_s - 1;
- for (int i = l / bl_s; i < blocks_s; i++) {
- if (L >= l && R <= r) {
- blocks[i].add(x);
- }else if ((l >= L && l <= R) || (r >= L && r <= R)) {
- blocks[i].addtoReal(max(0, l - L), min(R - L, r - L), x);
- }
- else {
- break;
- }
- if (i != blocks_s - 1) {
- L = R + 1;
- R = L + blocks[i + 1].real_s - 1;
- }
- }
- }
- if (type == '?') {
- L = (l / bl_s) * bl_s;
- R = L + blocks[l / bl_s].real_s -1;
- bool fl = 1;
- for (int i = l / bl_s; i < blocks_s; i++) {
- if (L >= l && R <= r) {
- if (blocks[i].contains(x)) {
- cout << "YES\n";
- fl = 0;
- break;
- }
- }
- else if ((l >= L && l <= R) || (r >= L && r <= R)) {
- if (blocks[i].contains_stupid(max(0, l - L), min(R - L, r - L), x)) {
- cout << "YES\n";
- fl = 0;
- break;
- }
- }
- else {
- break;
- }
- if (i != blocks_s - 1) {
- L = R + 1;
- R = L + blocks[i + 1].real_s - 1;
- }
- }
- if (fl) {
- cout << "NO\n";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement