闻灌佬多
  • 板块灌水区
  • 楼主OrientDragon
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/8/25 19:57
  • 上次更新2024/8/25 22:35:54
查看原帖
闻灌佬多
1173109
OrientDragon楼主2024/8/25 19:57

P4054 本地编译器能运行 结果交在洛谷上CE。。。

#include <bits/stdc++.h>
using namespace std;

int n, m, q, op, x1, y1, x2, y2, x, y, c;
const int N = 305, C = 105;
int a[N][N], tree[N][N][C];

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

void add_single(int x, int y, int color, int num) {
	for(int i = x; i <= n; i += lowbit(i))
		for(int j = y; j <= m; j += lowbit(j))
			tree[i][j][color] += num;
}

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

int search(int x1, int y1, int x2, int y2, int color) {
	return ask(x2, y2, color) - ask(x2, y1 - 1, color) - ask(x1 - 1, y2, color) + ask(x1 - 1, y1 - 1, color);
}

int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++) {
			cin >> a[i][j];
			add_single(i, j, a[i][j], 1);
		}
	cin >> q;
	while(q --) {
		cin >> op;
		if(op == 1) {
			cin >> x >> y >> c;
			add_single(x, y, a[x][y], -1);
			a[x][y] = c;
			add_single(x, y, a[x][y], 1);
		} else {
			cin >> x1 >> x2 >> y1 >> y2 >> c;
			cout << search(x1, y1, x2, y2, c) << endl;
		}
	}
}
2024/8/25 19:57
加载中...