-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathd.cpp
43 lines (40 loc) · 781 Bytes
/
d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int MOD = 998244353;
int T, N, M, K, Q;
int X[200000], Y[200000];
bool xd[200000], yd[200000];
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
while(T--){
eat >> N >> M >> K >> Q;
fill(xd, xd+N, 0);
fill(yd, yd+M, 0);
for(int i = 0; i < Q; i++){
eat >> X[i] >> Y[i];
X[i]--, Y[i]--;
}
int xf = N, yf = M;
int ans = 1;
for(int i = Q-1; i >= 0; i--){
bool bad = 0;
bool xfl = xd[X[i]] || !yf;
bool yfl = yd[Y[i]] || !xf;
bad = (xfl && yfl);
if(bad) continue;
ans = (ans * K) % MOD;
if(!xd[X[i]]){
xd[X[i]] = 1, xf--;
}
if(!yd[Y[i]]){
yd[Y[i]] = 1, yf--;
}
}
moo << ans << endl;
}
}