Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <cmath>
- #include <utility>
- #define pb emplace_back
- #define pii pair<int,int>
- #define F first
- #define S second
- /*
- 8e7 so dian
- FHVirus so dian
- youou so dian
- KYW so dian
- hubert so dian
- */
- //IO
- #define theyRSOOOOOOOOODIAN ios_base::sync_with_stdio(false),cin.tie(0);
- #define endl '\n'
- //workspace
- #define lowbit(x) (x & -x)
- int n;
- int bit[1030][1030];
- void modify(int x,int y,int k){
- for (;x<=n;x += lowbit(x)){
- for (int i=y;i<=n;i += lowbit(y)){
- bit[x][i] += k;
- }
- }
- }
- int query(int x,int y){
- int ans = 0;
- for (;x;x ^= lowbit(x)){
- for (int i=y;i;i ^= lowbit(i)){
- ans += bit[x][i];
- }
- }
- return ans;
- }
- int main(){
- theyRSOOOOOOOOODIAN
- char cmd;
- cin >> n;
- while (cin >> cmd){
- if (cmd == '1'){
- int x,y,z;
- cin >> x >> y >> z;
- modify(x+1,y+1,z);
- }
- else{
- int x_1,x_2,y_1,y_2;
- cin >> x_1 >> y_1 >> x_2 >> y_2;
- int ans = 0;
- ans += query(x_2+1,y_2+1);
- ans += query(x_1,y_1);
- ans -= query(x_1,y_2+1);
- ans -= query(x_2+1,y_1);
- cout << ans << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement