結果

問題 No.2230 Good Omen of White Lotus
ユーザー umezoumezo
提出日時 2023-02-26 07:55:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,752 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 209,656 KB
実行使用メモリ 8,052 KB
最終ジャッジ日時 2023-10-12 00:59:23
合計ジャッジ時間 9,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 37 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 56 ms
5,196 KB
testcase_17 AC 57 ms
5,068 KB
testcase_18 AC 56 ms
5,072 KB
testcase_19 AC 56 ms
5,168 KB
testcase_20 AC 5 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 6 ms
4,352 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 3 ms
6,104 KB
testcase_25 AC 4 ms
6,096 KB
testcase_26 AC 4 ms
6,116 KB
testcase_27 AC 78 ms
7,684 KB
testcase_28 AC 74 ms
7,684 KB
testcase_29 AC 81 ms
7,744 KB
testcase_30 AC 88 ms
7,792 KB
testcase_31 AC 86 ms
7,792 KB
testcase_32 AC 83 ms
7,720 KB
testcase_33 AC 124 ms
7,744 KB
testcase_34 AC 122 ms
7,856 KB
testcase_35 AC 123 ms
7,912 KB
testcase_36 AC 123 ms
8,012 KB
testcase_37 AC 123 ms
7,704 KB
testcase_38 AC 122 ms
8,052 KB
testcase_39 AC 121 ms
7,708 KB
testcase_40 AC 38 ms
6,468 KB
testcase_41 AC 37 ms
4,944 KB
testcase_42 AC 74 ms
5,084 KB
testcase_43 AC 8 ms
6,188 KB
testcase_44 AC 101 ms
6,192 KB
testcase_45 AC 39 ms
5,456 KB
testcase_46 AC 65 ms
6,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include<bits/stdc++.h>
using namespace std;

template <typename X>
struct SegTree{
  using FX=function<X(X,X)>;
  int n;
  FX fx;
  const X ex;
  vector<X> dat;
  SegTree(int n_,FX fx_,X ex_) : n(),fx(fx_),ex(ex_),dat(n_*4,ex_){
    int x=1;
    while (n_>x){
      x *= 2;
    }
    n=x;
  }
  void set(int i,X x){ dat[i+n-1]=x;}
  void build(){
    for (int k=n-2;k>=0;k--) dat[k]=fx(dat[2*k+1],dat[2*k+2]);
  }
  void update(int i,X x){
    i += n-1;
    dat[i]=x;
    while(i>0){
      i=(i-1)/2;
      dat[i]=fx(dat[i*2+1],dat[i*2+2]);
    }
  }
  X get(int i){return dat[i+n-1];}
  X all(){return dat[0];}
  X query(int a,int b){ return query_sub(a,b,0,0,n);}
  X query_sub(int a,int b,int k,int l,int r){
    if(r<=a || b<=l){
      return ex;
    }else if(a<=l && r<=b){
      return dat[k];
    }else{
      X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
      X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
      return fx(vl,vr);
    }
  }
};

const int MOD=998244353;
ll modpow(ll x,ll n){
  x%=MOD;
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w,n,p;
  cin>>h>>w>>n>>p;
  vector<pair<int,int>> P;
  rep(i,n){
    int x,y;
    cin>>x>>y;
    x--,y--;
    P.push_back({x,y});
  }
  sort(ALL(P));
  
  using X=int;
  auto fx=[](X x1,X x2)->X{ return max(x1,x2);};
  X ex=0;
  SegTree<X> seg(w,fx,ex);
  
  rep(i,n){
    int x=P[i].first,y=P[i].second;
    seg.update(y,seg.query(0,y+1)+1);
  }
  ll a=seg.all(),b=h+w-3-a;
  cout<<(1-modpow(p-2,a)*modpow(p-1,b)%MOD*modpow(modpow(p,h+w-3),MOD-2)%MOD+MOD)%MOD<<endl;

  return 0;
}
0