额,讨论版进不去,就在这里发了。
#include <iostream>
using namespace std;
int n, m, q, k, a[3][500005], cnt[3][500005];
long long ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m >> q >> k;
while (q--)
{
int op, x;
cin >> op >> x;
a[op][x] = (a[op][x] + 1) % k;
}
for (int i = 1; i <= n; i++)
cnt[1][a[1][i]]++;
for (int j = 1; j <= m; j++)
cnt[2][a[2][j]]++;
ans = n * m;
ans -= cnt[1][0] * cnt[2][0];
for (int i = 1; i <= k; i++)
ans -= cnt[1][i] * cnt[2][k - i];
cout << ans << "\n";
return 0;
}