记录编号 572037 评测结果 AAAAAAAAAA
题目名称 [IOI 2001] 移动电话 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.576 s
提交时间 2022-06-27 15:39:36 内存使用 6.96 MiB
显示代码纯文本
#include <bits/stdc++.h>

using i64 = long long;

const int N = 1050;
int s, op;
int c[N][N];

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

void add(int x, int y, int v) {
    for (int i = x; i <= s; i += lowbit(i)) 
        for (int j = y; j <= s; j += lowbit(j)) 
            c[i][j] += v;
}

int ask(int x, int y) {
    int t = 0;
    for (int i = x; i; i -= lowbit(i)) 
        for (int j = y; j; j -= lowbit(j)) 
            t += c[i][j]; 
    return t;
}

int main() {
    freopen("mobilephones.in", "r", stdin); 
    freopen("mobilephones.out", "w", stdout);
    std::cin >> op >> s;
    while (std::cin >> op, op != 3) {
        if (op == 1) {
            int x, y, a;
            std::cin >> x >> y >> a;
            ++ x, ++ y;
            add(x, y, a);
        } else {
            int l, b, r, t;
            std::cin >> l >> b >> r >> t;
            ++ l, ++ b, ++ r, ++ t;
            int res = ask(r, t) - ask(r, b - 1) - ask(l - 1, t) + ask(l - 1, b - 1);
            std::cout << res << '\n';
        }
    }
    return 0;
}