結果
問題 | No.2230 Good Omen of White Lotus |
ユーザー |
|
提出日時 | 2023-12-30 17:37:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 5,893 bytes |
コンパイル時間 | 2,440 ms |
コンパイル使用メモリ | 203,088 KB |
最終ジャッジ日時 | 2025-02-18 15:40:28 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define repd(i,a,b) for (ll i=(a);i<(b);i++)#define rep(i,n) repd(i,0,n)#define all(x) (x).begin(),(x).end()template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }typedef long long ll;typedef pair<ll,ll> P;typedef vector<ll> vec;typedef vector<vec> Graph;const long long INF = 1LL<<60;const long long MOD = 1000000007;// auto mod int// https://youtu.be/L8grWxBlIZ4?t=9858// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize// https://youtu.be/8uowVvQ_-Mo?t=1329 : divisionconst int mod = 998244353;struct mint {ll x; // typedef long long ll;mint(ll x=0):x((x%mod+mod)%mod){}mint operator-() const { return mint(-x);}mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}mint operator+(const mint a) const { return mint(*this) += a;}mint operator-(const mint a) const { return mint(*this) -= a;}mint operator*(const mint a) const { return mint(*this) *= a;}mint pow(ll t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}// for prime modmint inv() const { return pow(mod-2);}mint& operator/=(const mint a) { return *this *= a.inv();}mint operator/(const mint a) const { return mint(*this) /= a;}};istream& operator>>(istream& is, mint& a) { return is >> a.x;}ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}// https://github.com/atcoder/ac-library/#include <algorithm>#include <cassert>#include <vector>#ifdef _MSC_VER#include <intrin.h>#endifnamespace atcoder {namespace internal {int ceil_pow2(int n) {int x = 0;while ((1U << x) < (unsigned int)(n)) x++;return x;}constexpr int bsf_constexpr(unsigned int n) {int x = 0;while (!(n & (1 << x))) x++;return x;}int bsf(unsigned int n) {#ifdef _MSC_VERunsigned long index;_BitScanForward(&index, n);return index;#elsereturn __builtin_ctz(n);#endif}} // namespace internal} // namespace atcodernamespace atcoder {template <class S, S (*op)(S, S), S (*e)()> struct segtree {public:segtree() : segtree(0) {}explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {log = internal::ceil_pow2(_n);size = 1 << log;d = std::vector<S>(2 * size, e());for (int i = 0; i < _n; i++) d[size + i] = v[i];for (int i = size - 1; i >= 1; i--) {update(i);}}void set(int p, S x) {assert(0 <= p && p < _n);p += size;d[p] = x;for (int i = 1; i <= log; i++) update(p >> i);}S get(int p) const {assert(0 <= p && p < _n);return d[p + size];}S prod(int l, int r) const {assert(0 <= l && l <= r && r <= _n);S sml = e(), smr = e();l += size;r += size;while (l < r) {if (l & 1) sml = op(sml, d[l++]);if (r & 1) smr = op(d[--r], smr);l >>= 1;r >>= 1;}return op(sml, smr);}S all_prod() const { return d[1]; }template <bool (*f)(S)> int max_right(int l) const {return max_right(l, [](S x) { return f(x); });}template <class F> int max_right(int l, F f) const {assert(0 <= l && l <= _n);assert(f(e()));if (l == _n) return _n;l += size;S sm = e();do {while (l % 2 == 0) l >>= 1;if (!f(op(sm, d[l]))) {while (l < size) {l = (2 * l);if (f(op(sm, d[l]))) {sm = op(sm, d[l]);l++;}}return l - size;}sm = op(sm, d[l]);l++;} while ((l & -l) != l);return _n;}template <bool (*f)(S)> int min_left(int r) const {return min_left(r, [](S x) { return f(x); });}template <class F> int min_left(int r, F f) const {assert(0 <= r && r <= _n);assert(f(e()));if (r == 0) return 0;r += size;S sm = e();do {r--;while (r > 1 && (r % 2)) r >>= 1;if (!f(op(d[r], sm))) {while (r < size) {r = (2 * r + 1);if (f(op(d[r], sm))) {sm = op(d[r], sm);r--;}}return r + 1 - size;}sm = op(d[r], sm);} while ((r & -r) != r);return 0;}private:int _n, size, log;std::vector<S> d;void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }};} // namespace atcoderusing namespace atcoder;ll op(ll x,ll y){return max(x,y);}ll e(){return 0;}int main(){ios::sync_with_stdio(false);cin.tie(0);ll h,w;cin>>h>>w;ll n,p;cin>>n>>p;Graph g(h+1);rep(i,n){ll x,y;cin>>x>>y;g[x].push_back(y);}segtree<ll,op,e> t(w+2);rep(i,h+1){sort(all(g[i]));for(auto x:g[i]){ll now=t.prod(0,x+1);t.set(x,now+1);}}ll cnt=t.all_prod();mint a=1;mint b=2;a/=p;b/=p;mint A=1,B=1;A-=a;B-=b;mint ans=1;mint sub=mint(A).pow(h+w-3-cnt)*mint(B).pow(cnt);ans-=sub;cout<<ans<<endl;return 0;}