其他分享
首页 > 其他分享> > Luogu P4514 上帝造题的七分钟

Luogu P4514 上帝造题的七分钟

作者:互联网

题目链接:传送门

二维树状数组
区间加区间求和
烦人的输入

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define A 1000010
#define B 2049

using namespace std;
typedef long long ll;
int t1[B][B], t2[B][B], t3[B][B], t4[B][B], delta;
int n, m, a, b, c, d; char opt[1];
int lowbit(int x) {return x & -x;}
void add(int x, int y, ll ad) {
	for (int i = x; i <= n; i += lowbit(i))
		for (int j = y; j <= m; j += lowbit(j)) {
			t1[i][j] += ad;
			t2[i][j] += ad * x;
			t3[i][j] += ad * y;
			t4[i][j] += ad * x * y;
		}
}
void addval() {
	add(a, b, delta); add(a, d + 1, -delta);
	add(c + 1, b, -delta); add(c + 1, d + 1, delta);
}
int ask(int x, int y, int ans = 0) {
	for (int i = x; i; i -= lowbit(i))
		for (int j = y; j; j -= lowbit(j))
			ans += (x + 1) * (y + 1) * t1[i][j] - (y + 1) * t2[i][j] - (x + 1) * t3[i][j] + t4[i][j];
	return ans;
}

int main(int argc, char const *argv[]) {
	scanf("X %d%d", &n, &m);
	while (~scanf("%s", &opt)) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		if (opt[0] == 'L') scanf("%d", &delta), addval();
		else printf("%d\n", ask(c, d) - ask(c, b - 1) - ask(a - 1, d) + ask(a - 1, b - 1));
	}
	return 0;
}

标签:int,Luogu,ll,long,七分钟,造题,include,define
来源: https://blog.csdn.net/yandaoqiusheng/article/details/90137896