比赛 EYOI暨SBOI暑假快乐赛3rd 评测结果 AAAAAAAAAA
题目名称 移动电话 最终得分 100
用户昵称 cb 运行时间 0.921 s
代码语言 C++ 内存使用 15.29 MiB
提交时间 2022-06-27 09:40:08
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long 
using namespace std;

ll x, y, a, l ,b , r, t, sb, s, mar[1025][1025] = {0}, c[1030][1030] = {0};

int lowbit (int r1) {
    return (r1 & -r1);
}

void add (int r1, int r2) {
    for (; r2 <= s; r2 += lowbit (r2)) {
        c[r1][r2] += a;
    }
    return ;
}

ll sum (int hang, int r1, int r2) {
    ll ans1 = 0, ans2 = 0;
    r1 --;
    for (; r1; r1 -= lowbit (r1)) {
        ans1 += c[hang][r1];
    }
    for (; r2; r2 -= lowbit (r2)) {
        ans2 += c[hang][r2];
    }
    return (ans2 - ans1);
}

ll ask (int r1, int r2, int t1, int t2) {
    ll ans = 0;
    for (int q = r1; q <= t1; ++q) {
        ans += sum (q, r2, t2);
    }
    return ans;
}

void print () {
    for (int q = 1; q <= s; ++q) {
        for (int w = 1; w <= s; ++w) {
            printf ("%d ", c[q][w]);
        }printf ("\n");
    }
}

int main () {
    freopen ("mobilephones.in", "r", stdin);
    freopen ("mobilephones.out", "w", stdout);
    cin >> sb >> s;
    while (cin >> sb) {
        if (sb == 1) {
            cin >> x >> y >> a;
            x ++; y ++; add (x, y);
        }
        if (sb == 2) {
            cin >> l >> b >> r >> t;
            l ++; b ++ ;r ++ ;t ++;
            cout << ask (l ,b, r, t) << endl;
        }
        if (sb == 3) {
            break;
        }
    }
    return 0;
}