結果

問題 No.2571 列辞書順列
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-12-02 16:27:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,511 bytes
コンパイル時間 4,383 ms
コンパイル使用メモリ 271,120 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2023-12-09 18:08:51
合計ジャッジ時間 8,191 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 26 ms
6,548 KB
testcase_03 AC 26 ms
6,548 KB
testcase_04 AC 50 ms
6,548 KB
testcase_05 AC 50 ms
6,548 KB
testcase_06 AC 75 ms
7,296 KB
testcase_07 AC 72 ms
7,296 KB
testcase_08 AC 56 ms
7,296 KB
testcase_09 AC 54 ms
7,296 KB
testcase_10 AC 66 ms
7,296 KB
testcase_11 AC 67 ms
7,296 KB
testcase_12 AC 67 ms
7,296 KB
testcase_13 AC 65 ms
7,296 KB
testcase_14 AC 66 ms
7,296 KB
testcase_15 AC 67 ms
7,296 KB
testcase_16 AC 67 ms
7,296 KB
testcase_17 AC 67 ms
7,296 KB
testcase_18 AC 71 ms
7,296 KB
testcase_19 AC 67 ms
7,296 KB
testcase_20 AC 66 ms
7,296 KB
testcase_21 AC 68 ms
7,296 KB
testcase_22 AC 66 ms
7,296 KB
testcase_23 AC 67 ms
7,296 KB
testcase_24 AC 66 ms
7,296 KB
testcase_25 AC 73 ms
7,296 KB
testcase_26 AC 68 ms
7,296 KB
testcase_27 AC 68 ms
7,296 KB
testcase_28 AC 68 ms
7,296 KB
testcase_29 AC 67 ms
7,296 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}

using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

using mint = modint998244353;
using vm = vector<mint>;
using vvm = vector<vm>;
inline ostream& operator<<(ostream& os, const mint P) { return os << P.val(); };

using P = pair<mint, mint>;
P op(P x, P y) { return P{x.first + y.first, x.second + y.second}; }
P e() { return P{0, 0}; }

void solve() {
  int n, m, k, q;
  cin >> n >> m >> k >> q;
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  if (m == 1) {
    while (q--) {
      int type;
      cin >> type;
      if (type == 1) {
        int l, r;
        cin >> l >> r;
        cout << (r - l) << "\n";
      } else {
        int x, y;
        cin >> x >> y;
        a[x - 1] = y;
      }
    }
  } else {
    mint inv = mint(m).inv();
    vm m_pow(n + 1), inv_pow(n + 1);
    m_pow[0] = 1;
    inv_pow[0] = 1;
    rep(i, 0, n) {
      m_pow[i + 1] = m_pow[i] * m;
      inv_pow[i + 1] = inv_pow[i] * inv;
    }
    mint div = mint(m - 1).inv();

    segtree<P, op, e> seg(n);
    rep(i, 0, n) {
      a[i]--;
      seg.set(i, P{a[i], a[i] * inv_pow[i]});
    }

    mint pow_k = mint(m).pow(k);

    while (q--) {
      int type;
      cin >> type;
      if (type == 1) {
        int l, r;
        cin >> l >> r;
        l--;
        auto prod = seg.prod(l, r);
        mint u = prod.first, v = prod.second;
        mint ans = (v * pow_k * m_pow[l] - u) * div + r - l;
        cout << ans << "\n";
      } else {
        int x, y;
        cin >> x >> y;
        x--, y--;
        a[x] = y;
        seg.set(x, P{y, y * inv_pow[x]});
      }
    }
  }
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) solve();
}
0