Advertisement
yungyao

Untitled

Dec 27th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. using namespace std;
  2. #include <iostream>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <utility>
  8.  
  9. #define pb emplace_back
  10. #define pii pair<int,int>
  11. #define F first
  12. #define S second
  13.  
  14. /*
  15. 8e7 so dian
  16. FHVirus so dian
  17. youou so dian
  18. KYW so dian
  19. hubert so dian
  20. */
  21.  
  22. //IO
  23. #define theyRSOOOOOOOOODIAN ios_base::sync_with_stdio(false),cin.tie(0);
  24. #define endl '\n'
  25.  
  26. //workspace
  27. #define lowbit(x) (x & -x)
  28.  
  29. int n;
  30. int bit[1030][1030];
  31.  
  32. void modify(int x,int y,int k){
  33.     for (;x<=n;x += lowbit(x)){
  34.         for (int i=y;i<=n;i += lowbit(y)){
  35.             bit[x][i] += k;
  36.         }
  37.     }
  38. }
  39.  
  40. int query(int x,int y){
  41.     int ans = 0;
  42.     for (;x;x ^= lowbit(x)){
  43.         for (int i=y;i;i ^= lowbit(i)){
  44.             ans += bit[x][i];
  45.         }
  46.     }
  47.     return ans;
  48. }
  49.  
  50. int main(){
  51.     theyRSOOOOOOOOODIAN
  52.     char cmd;
  53.  
  54.     cin >> n;
  55.     while (cin >> cmd){
  56.         if (cmd == '1'){
  57.             int x,y,z;
  58.  
  59.             cin >> x >> y >> z;
  60.             modify(x+1,y+1,z);
  61.         }
  62.         else{
  63.             int x_1,x_2,y_1,y_2;
  64.  
  65.             cin >> x_1 >> y_1 >> x_2 >> y_2;
  66.             int ans = 0;
  67.             ans += query(x_2+1,y_2+1);
  68.             ans += query(x_1,y_1);
  69.             ans -= query(x_1,y_2+1);
  70.             ans -= query(x_2+1,y_1);
  71.  
  72.             cout << ans << '\n';
  73.         }
  74.     }
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement