20pts,求助,想知道自己的思路是不是有问题
查看原帖
20pts,求助,想知道自己的思路是不是有问题
1019606
KouMoSir楼主2023/8/27 11:19
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll n, m, q, k, ans, op, x;
ll l[N], c[N], numl, numc;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m >> q >> k;
	while (q--) {
		cin >> op >> x;
		if (op == 1) {
			if (!l[x])numl++;
			l[x]++;
		}
		else {
			if (!c[x])numc++;
			c[x]++;
		}
	}
	ans = numl * m + numc * n - numl * numc;
	//现在的ans等于所有被涂色过的格子数
	sort(c + 1, c + m + 1);
	//将每一列的涂色次数排序小到大
	for (int i = 1; i <= n; i++) {
		ll tmp = k - l[i];
		//要排除涂色k次的格子,现在每一行涂色l[i]次,找到有多少列涂色k-l[i]次
		ll len = upper_bound(c + 1, c + m + 1, tmp) - lower_bound(c + 1, c + m + 1, tmp);
		ans -= len;
	}
	cout << ans;
}
2023/8/27 11:19
加载中...