Advertisement
bibaboba12345

оцени анимедевочку от 1 до 10

Aug 23rd, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cmath>
  6. using namespace std;
  7. const int N = 1e5+7;
  8. int blockLen;
  9. int arr[N];
  10. struct Block {
  11. int real[101], sorted[101], real_s;
  12. int delta;
  13. Block() {
  14. delta = 0;
  15. real_s = 0;
  16. }
  17. void addtoReal(int l, int r, int x) {
  18. for (int i = 0; i < real_s; i++) {
  19. if (i >= l && i <= r) {
  20. real[i] += x;
  21. }
  22. real[i] += delta;
  23. sorted[i] = real[i];
  24. }
  25. delta = 0;
  26. sort(sorted, sorted + real_s);
  27. }
  28. void add(int x) {
  29. delta += x;
  30. }
  31. bool contains(int x) {
  32. int L = 0;
  33. int R = real_s - 1;
  34. while (R - L > 1) {
  35. int mid = (R + L) / 2;
  36. if (sorted[mid] + delta == x) {
  37. return 1;
  38. }
  39. if (sorted[mid] + delta < x) {
  40. L = mid;
  41. }
  42. else {
  43. R = mid;
  44. }
  45. }
  46. if (sorted[L] + delta == x || sorted[R] + delta == x) {
  47. return 1;
  48. }
  49. else {
  50. return 0;
  51. }
  52. }
  53. bool contains_stupid(int l, int r, int x) {
  54. for (int i = l; i <= r; i++) {
  55. if (real[i] + delta == x) {
  56. return 1;
  57. }
  58. }
  59. return 0;
  60. }
  61.  
  62. };
  63. int n, bl_s, m, l,r,x,L,R;
  64. Block blocks[1003];
  65. int blocks_s = 0;
  66. char type;
  67. int main()
  68. {
  69. ios_base::sync_with_stdio(false);
  70. cin.tie(0);
  71. cout.tie(0);
  72. cin >> n >> m;
  73. bl_s = 100;
  74. Block bl;
  75. for (int i = 0; i < n; i++) {
  76. cin >> arr[i];
  77. if ((i % bl_s == 0 && i != 0)){
  78. sort(bl.sorted, bl.sorted + bl.real_s);
  79. blocks[blocks_s] = (bl);
  80. blocks_s++;
  81. bl.real_s = 1;
  82. bl.real[0] = (arr[i]);
  83. bl.sorted[0] = (arr[i]);
  84. }
  85. else {
  86. bl.real[bl.real_s] = (arr[i]);
  87. bl.sorted[bl.real_s] = (arr[i]);
  88. bl.real_s++;
  89. }
  90. }
  91. sort(bl.sorted, bl.sorted+bl.real_s);
  92. blocks[blocks_s] = (bl);
  93. blocks_s++;
  94. for (int I = 0; I < m; I++) {
  95. cin >> type >> l >> r >> x;
  96. l--;
  97. r--;
  98. if (type == '+') {
  99. L = (l / bl_s) * bl_s;
  100. R = L + blocks[l/bl_s].real_s - 1;
  101. for (int i = l / bl_s; i < blocks_s; i++) {
  102. if (L >= l && R <= r) {
  103. blocks[i].add(x);
  104. }else if ((l >= L && l <= R) || (r >= L && r <= R)) {
  105. blocks[i].addtoReal(max(0, l - L), min(R - L, r - L), x);
  106. }
  107. else {
  108. break;
  109. }
  110. if (i != blocks_s - 1) {
  111. L = R + 1;
  112. R = L + blocks[i + 1].real_s - 1;
  113. }
  114. }
  115. }
  116. if (type == '?') {
  117. L = (l / bl_s) * bl_s;
  118. R = L + blocks[l / bl_s].real_s -1;
  119. bool fl = 1;
  120. for (int i = l / bl_s; i < blocks_s; i++) {
  121. if (L >= l && R <= r) {
  122. if (blocks[i].contains(x)) {
  123. cout << "YES\n";
  124. fl = 0;
  125. break;
  126. }
  127. }
  128. else if ((l >= L && l <= R) || (r >= L && r <= R)) {
  129. if (blocks[i].contains_stupid(max(0, l - L), min(R - L, r - L), x)) {
  130. cout << "YES\n";
  131. fl = 0;
  132. break;
  133. }
  134. }
  135. else {
  136. break;
  137. }
  138. if (i != blocks_s - 1) {
  139. L = R + 1;
  140. R = L + blocks[i + 1].real_s - 1;
  141. }
  142. }
  143. if (fl) {
  144. cout << "NO\n";
  145. }
  146. }
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement