社区讨论

abc D题求调!!崩

学术版参与者 8已保存回复 10

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
9 条
当前快照
1 份
快照标识符
@lpo524o6
此快照首次捕获于
2023/12/02 22:18
2 年前
此快照最后确认于
2023/12/03 09:39
2 年前
查看原帖
就是把他分成中间一堆整块,周围一堆散块来做。给个 hack 数据也行!!!
C
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 1005;

int n, m, sum[N][N];
char a[N][N];

int get(int a, int b,int c, int d) {
	if (a > c || b > d) return 0;
	return sum[c][d] - sum[a - 1][d] - sum[c][b - 1] + sum[a - 1][b - 1];
}

signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cin >> a[i][j], sum[i][j] = (a[i][j] == 'B');
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) sum[i][j] += sum[i][j - 1];
			if (i) sum[i][j] += sum[i - 1][j];
			if (i && j)sum[i][j] -= sum[i - 1][j - 1];
		}
	}
	while (m--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		int aa = a % n, bb = b % n, cc = c % n, dd = d % n;
		
		
		int pos1 = a;
		while (1) {
			if (pos1 % n == n - 1) break;
			pos1++;
		}
		int pos2 = c;
		while (1) {
			if (pos2 % n == 0) break;
			pos2--;
		}
		int pos3 = b;
		while (1) {
			if (pos3 % n == n - 1) break;
			pos3++;
		}
		int pos4 = d;
		while (1) {
			if (pos4 % n == 0) break;
			pos4--;
		}
//		cout << pos1 << ' ' << pos2 << ' ' << pos3 << ' ' << pos4 << endl;
		int J = get(aa, bb, n - 1, n - 1) + get(0, bb, cc, n - 1) + get(aa, 0, n - 1, dd) + get(0, 0, cc, dd);
		int tt = get(aa, 0, n - 1, n - 1) * (pos4 - 1 - (pos3 + 1) + 1) / n
			+ get(0, 0, cc, n - 1) * (pos4 - 1 - (pos3 + 1) + 1) / n
			+ get(0, bb, n - 1, n - 1) * (pos2 - 1 - (pos1 + 1) + 1) / n
			+ get(0, 0, n - 1, dd) * (pos2 - 1 - (pos1 + 1) + 1) / n;
		int ll = get(0, 0, n - 1, n - 1) * (pos4 - 1 - (pos3 + 1) + 1) / n * (pos2 - 1 - (pos1 + 1) + 1) / n;
		
//		cout << J << ' ' << tt << ' ' << ll << endl; 
		cout << J + tt + ll << endl;	 
	}
}

回复

10 条回复,欢迎继续交流。

正在加载回复...