MAGCARI

Kang Block

Sep 18th, 2021
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. /*
  2.     Author  : ~Aphrodicez
  3.     School  : RYW
  4.     Lang    : CPP
  5.     Algo    :
  6.     Status  :
  7. */
  8.  
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11.  
  12. #define x first
  13. #define y second
  14. #define pb push_back
  15. #define eb emplace_back
  16. #define all(a) (a).begin(), (a).end()
  17. #define SZ(a) (int)(a).size()
  18. #define pc(x) putchar(x)
  19. #define MP make_pair
  20. #define dec(x) fixed << setprecision(x)
  21. #define v(a) vector <a>
  22. #define p(a, b) pair <a, b>
  23. #define heap(a) priority_queue <a>
  24.  
  25. using i64 = long long;
  26.  
  27. void setIO();
  28.  
  29. const int d4i[] = {-1, 0, 1, 0};
  30. const int d4j[] = {0, 1, 0, -1};
  31. const int d8i[] = {-1, -1, 0, 1, 1, 1, 0, -1};
  32. const int d8j[] = {0, 1, 1, 1, 0, -1, -1, -1};
  33.  
  34. struct GRAPH {
  35.    
  36. };
  37.  
  38. const int MaxN = 2e3 + 10;
  39. const int MaxM = 2e5 + 10;
  40.  
  41. void TESTCASE() {
  42.    
  43. }
  44.  
  45. int r, c;
  46.  
  47. long long tree[MaxN];
  48.  
  49. void upd(int idx, long long val) {
  50.     while(idx <= r + c) {
  51.         tree[idx] += val;
  52.         idx += (idx & -idx);
  53.     }
  54. }
  55.  
  56. int query(int idx) {
  57.     long long sum = 0;
  58.     while(idx > 0) {
  59.         sum += tree[idx];
  60.         idx -= (idx & -idx);
  61.     }
  62.     return sum;
  63. }
  64.  
  65. void solve() {
  66.     int k, q;
  67.     cin >> r >> c >> k >> q;
  68.     q += k;
  69.     int opr;
  70.     while(q--) {
  71.         cin >> opr;
  72.         int i, j;
  73.         cin >> i >> j;
  74.         j += (i - 1);
  75.         if(opr == 1) {
  76.             int sz;
  77.             cin >> sz;
  78.             int l = j;
  79.             r = l + sz - 1;
  80.             upd(l, 1);
  81.             upd(r + 1, -1);
  82.         }
  83.         if(opr == 2) {
  84.             int idx = j;
  85.             cout << query(idx) << "\n";
  86.         }
  87.     }
  88. }
  89.  
  90. int main() {
  91.     setIO();
  92.     int q = 1;
  93.    
  94.     for(int i = 1; i <= q; i++) {
  95.         solve();
  96.     }
  97.     return 0;
  98. }
  99.  
  100. void setIO() {
  101.     ios_base :: sync_with_stdio(0);
  102.     cin.tie(0);
  103. }
  104.  
  105. /*
  106. 5 5 6 5
  107. 1 1 1 4
  108. 1 1 3 3
  109. 2 3 2
  110. 1 2 1 5
  111. 1 2 4 2
  112. 1 2 4 2
  113. 1 4 2 3
  114. 2 4 2
  115. 2 1 4
  116. 2 5 3
  117. 2 5 5
  118. */
Advertisement
Add Comment
Please, Sign In to add comment