結果

問題 No.2230 Good Omen of White Lotus
ユーザー tnakao0123tnakao0123
提出日時 2023-04-24 11:54:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 2,952 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 59,612 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-26 01:46:50
合計ジャッジ時間 5,658 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 34 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 48 ms
5,376 KB
testcase_17 AC 48 ms
5,504 KB
testcase_18 AC 49 ms
5,504 KB
testcase_19 AC 49 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,632 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 62 ms
7,168 KB
testcase_28 AC 62 ms
7,040 KB
testcase_29 AC 69 ms
6,944 KB
testcase_30 AC 74 ms
7,040 KB
testcase_31 AC 71 ms
6,912 KB
testcase_32 AC 71 ms
7,040 KB
testcase_33 AC 104 ms
6,912 KB
testcase_34 AC 103 ms
6,940 KB
testcase_35 AC 104 ms
6,944 KB
testcase_36 AC 104 ms
6,912 KB
testcase_37 AC 104 ms
6,912 KB
testcase_38 AC 106 ms
7,040 KB
testcase_39 AC 103 ms
6,912 KB
testcase_40 AC 32 ms
6,016 KB
testcase_41 AC 31 ms
5,376 KB
testcase_42 AC 63 ms
5,376 KB
testcase_43 AC 7 ms
5,760 KB
testcase_44 AC 84 ms
6,016 KB
testcase_45 AC 32 ms
5,376 KB
testcase_46 AC 56 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2230.cc:  No.2230 Good Omen of White Lotus - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_H = 200000;
const int MAX_W = 200000;
const int MAX_N = 200000;
const int MOD = 998244353;

/* typedef */

typedef pair<int,int> pii;

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

typedef MI<MOD> mi;

template <typename T>
struct SegTreeMax {
  int e2;
  vector<T> nodes;
  T defv;
  SegTreeMax() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    nodes.assign(e2 * 2, defv);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { geti(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = max(nodes[j * 2 + 1], nodes[j * 2 + 2]);
  }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = max(nodes[j * 2 + 1], nodes[j * 2 + 2]);
    }
  }

  T max_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = max_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = max_range(r0, r1, k * 2 + 2, im, i1);
    return max(v0, v1);
  }
  T max_range(int r0, int r1) { return max_range(r0, r1, 0, 0, e2); }
};

/* global variables */

pii ps[MAX_N];
SegTreeMax<int> st;

/* subroutines */

/* main */

int main() {
  int h, w, n, p;
  scanf("%d%d%d%d", &h, &w, &n, &p);

  for (int i = 0; i < n; i++) {
    int xi, yi;
    scanf("%d%d", &xi, &yi);
    xi--, yi--;
    ps[i] = pii(xi, yi);
  }
  sort(ps, ps + n);

  st.init(w, 0);
  for (int i = 0; i < n; i++) {
    int xi = ps[i].first, yi = ps[i].second;
    int v = st.max_range(0, yi + 1);
    st.set(yi, v + 1);
  }

  int m = h + w - 3;
  int z = st.max_range(0, w);
  //printf("z=%d\n", z);

  mi mp = mi(1) - mi(p - 1).pow(m - z) * mi(p - 2).pow(z) / mi(p).pow(m);
  printf("%d\n", mp.v);
  return 0;
}
0