Advertisement
bibaboba12345

Untitled

Dec 9th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. // clang-format off
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <bitset>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <random>
  9. #include <map>
  10. #include <string>
  11. #include <set>
  12. #include <deque>
  13. #include <cassert>
  14.  
  15.  
  16.  
  17. const int N = 3e5 + 7, A = 26, C = 2, MOD = 998244353, bl = 350;
  18. const long long INF = 1e18;
  19. using namespace std;
  20. using ll = long long;
  21. using ld = long double;
  22.  
  23. const ld EPS = 1e-9;
  24. int n, m;
  25.  
  26.  
  27. struct Block {
  28. bool snow[bl];
  29. int cnt[bl];
  30. int add_to_uncovered, add_to_covered, add_to_all;
  31. int full;
  32. void init() {
  33. for (int i = 0; i < bl; i++) {
  34. snow[i] = 0;
  35. cnt[i] = m;
  36. }
  37. full = -1; // 0 - не заполнять, 1 - заполнять снегом, -1 - заполнять отсутсвием снега
  38. add_to_uncovered = 0;
  39. add_to_covered = 0;
  40. add_to_all = 0;
  41. }
  42. void process() {
  43. for (int i = 0; i < bl; i++) {
  44. if (snow[i]) {
  45. cnt[i] += add_to_covered;
  46. }
  47. else {
  48. cnt[i] += add_to_uncovered;
  49. }
  50. cnt[i] += add_to_all;
  51. }
  52. add_to_covered = 0;
  53. add_to_uncovered = 0;
  54. add_to_all = 0;
  55. if (full == 0) {
  56. return;
  57. }
  58. if (full == -1) {
  59. for (int i = 0; i < bl; i++) {
  60. snow[i] = 0;
  61. }
  62. }
  63. else {
  64. for (int i = 0; i < bl; i++) {
  65. snow[i] = 1;
  66. }
  67. }
  68. full = 0;
  69. }
  70. void cover(int x) {
  71. if (full == -1) {
  72. add_to_all -= x;
  73. full = 1;
  74. return;
  75. }
  76. if (full == 1) {
  77. return;
  78. }
  79. full = 1;
  80. add_to_uncovered -= x;
  81. }
  82. void clear(int x) {
  83. if (full == -1) {
  84. return;
  85. }
  86. if (full == 1) {
  87. add_to_all += x;
  88. full = -1;
  89. return;
  90. }
  91. full = -1;
  92. add_to_covered += x;
  93. }
  94. void cover(int l, int r, int x) {
  95. process();
  96. for (int i = l; i <= r; i++) {
  97. if (!snow[i]) {
  98. cnt[i] -= x;
  99. snow[i] = 1;
  100. }
  101. }
  102. }
  103. void clear(int l, int r, int x) {
  104. process();
  105. for (int i = l; i <= r; i++) {
  106. if (snow[i]) {
  107. cnt[i] += x;
  108. snow[i] = 0;
  109. }
  110. }
  111. }
  112. };
  113.  
  114. Block b[N / bl];
  115.  
  116. void cover(int l, int r, int x) {
  117. int L = 0, R = bl - 1;
  118. for (int i = 0; i <= n / bl; i++) {
  119. int l1 = max(L, l);
  120. int r1 = min(r, R);
  121. if (r1 >= l1) {
  122. if (r1 - l1 + 1 == bl) {
  123. b[i].cover(x);
  124. }
  125. else {
  126. b[i].cover(l1 - L, r1 - L, x);
  127. }
  128. }
  129. L = R + 1;
  130. R = L + bl - 1;
  131. }
  132. }
  133.  
  134. void clear(int l, int r, int x) {
  135. int L = 0, R = bl - 1;
  136. for (int i = 0; i <= n / bl; i++) {
  137. int l1 = max(L, l);
  138. int r1 = min(r, R);
  139. if (r1 >= l1) {
  140. if (r1 - l1 + 1 == bl) {
  141. b[i].clear(x);
  142. }
  143. else {
  144. b[i].clear(l1 - L, r1 - L, x);
  145. }
  146. }
  147. L = R + 1;
  148. R = L + bl - 1;
  149. }
  150. }
  151.  
  152. signed main() {
  153. #ifdef _DEBUG
  154. freopen("input.txt", "r", stdin);
  155. #else
  156. std::ios::sync_with_stdio(false);
  157. cin.tie(0);
  158. #endif
  159. cin >> n >> m;
  160. for (int i = 0; i <= n / bl; i++) {
  161. b[i].init();
  162. }
  163. for (int i = 0; i < m; i++) {
  164. int cnt_days = m - i;
  165. char t;
  166. int l, r;
  167. cin >> t >> l >> r;
  168. l--;
  169. r--;
  170. if (t == '+') {
  171. cover(l, r, cnt_days);
  172. }
  173. else {
  174. clear(l, r, cnt_days);
  175. }
  176. }
  177. for (int i = 0; i <= n / bl; i++) {
  178. b[i].process();
  179. }
  180. for (int i = 0; i < n; i++) {
  181. cout << b[i / bl].cnt[i % bl] << " ";
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement