求助 WA#20 95pts
查看原帖
求助 WA#20 95pts
694274
yugen楼主2023/8/26 22:19
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<vector>
#include<queue>
#include<map> 
#include<set>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	int n, m, q, k;
	cin >> n >> m >> q >> k;
	map<int, int> row, col;
	while(q -- ) {
	    int op, x;
	    cin >> op >> x;
	    if(op == 1) {
	        row[x] ++ ;
	        if(row[x] >= k) row[x] -= k;
	    }
	    else {
	        col[x] ++ ;
	        if(col[x] >= k) col[x] -= k;
	    }
	}
	ll ans = 0, sum = 0;
	vector<int> hh(k + 1); 
	for(auto [num, cnt] : col) {
	    if(cnt != 0) sum ++ ;
	    hh[cnt] ++ ;
	}
	for(auto [num, cnt] : row) {
	    if(cnt == 0) ans += sum;
	    else ans += m - hh[k - cnt];
	}
	for(auto [num, cnt] : col) {
	    if(cnt != 0) ans += n - row.size();
	}
	cout << ans << '\n';
	
	return 0;
}
2023/8/26 22:19
加载中...