Advertisement
MinhNGUYEN2k4

Untitled

Feb 22nd, 2022
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. //Nguyen Huu Hoang Minh
  2. #include <bits/stdc++.h>
  3. #define sz(x) int(x.size())
  4. #define all(x) x.begin(),x.end()
  5. #define reset(x) memset(x, 0,sizeof(x))
  6. #define pb push_back
  7. #define mp make_pair
  8. #define fi first
  9. #define se second
  10. #define N 200005
  11. #define remain(x) if (x > MOD) x -= MOD
  12. #define ii pair<int, int>
  13. #define iiii pair< ii , ii >
  14. #define viiii vector< iiii >
  15. #define vi vector<int>
  16. #define vii vector< ii >
  17. #define bit(x, i) (((x) >> (i)) & 1)
  18. #define Task "test"
  19.  
  20. using namespace std;
  21.  
  22. typedef long double ld;
  23.  
  24. int t, n, m, k, q;
  25.  
  26. void readfile()
  27. {
  28.     ios_base::sync_with_stdio(false);
  29.     cin.tie(0);cout.tie(0);
  30.     if (fopen(Task".inp","r"))
  31.     {
  32.         freopen(Task".inp","r",stdin);
  33.         //freopen(Task".out","w",stdout);
  34.     }
  35.     cin >> t;
  36. }
  37.  
  38. int Pow(int a, int mu, int mod){
  39.     if (mu==1) return a;
  40.     int tmp = Pow(a,mu/2,mod);
  41.     if (mu%2==0) return tmp*tmp%mod;
  42.     return tmp*tmp%mod*a%mod;
  43. }
  44.  
  45. void solve(){
  46.     cin >> n >> m >> k >> q;
  47.     vii color(q);
  48.     for(int i=0; i<q; i++){
  49.         cin >> color[i].fi >> color[i].se;
  50.         color[i].fi--; color[i].se--;
  51.     }
  52.     int tplt = 0;
  53.     int ir = 0, ic = 0;
  54.     vector<bool> xc(n,0), yc(m,0);
  55.     for(int i=q-1; i>0; i--){
  56.         int cr = color[i].fi, cc = color[i].se;
  57.         if (xc[cr] && yc[cc]) continue;
  58.         while (ir < n && xc[ir]) ir++;
  59.         while (ic < m && yc[ic]) ic++;
  60.         if (ir==n || ic==m) continue;
  61.         xc[cr]=1; yc[cc] = 1;
  62.         tplt++;
  63.     }
  64.     const int mod = 998244353;
  65.     cout << Pow(k,tplt,mod) << '\n';
  66. }
  67.  
  68. void proc()
  69. {
  70.     while (t--){
  71.         solve();
  72.     }
  73. }
  74.  
  75. signed main()
  76. {
  77.     readfile();
  78.     proc();
  79.     return 0;
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement