結果

問題 No.2571 列辞書順列
ユーザー KudeKude
提出日時 2023-12-14 23:21:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 3,000 ms
コード長 1,972 bytes
コンパイル時間 3,161 ms
コンパイル使用メモリ 277,004 KB
実行使用メモリ 8,364 KB
最終ジャッジ日時 2023-12-14 23:22:01
合計ジャッジ時間 9,779 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 33 ms
6,676 KB
testcase_03 AC 33 ms
6,676 KB
testcase_04 AC 67 ms
6,676 KB
testcase_05 AC 67 ms
6,676 KB
testcase_06 AC 101 ms
8,364 KB
testcase_07 AC 100 ms
8,364 KB
testcase_08 AC 69 ms
8,364 KB
testcase_09 AC 66 ms
8,364 KB
testcase_10 AC 87 ms
8,364 KB
testcase_11 AC 88 ms
8,364 KB
testcase_12 AC 85 ms
8,364 KB
testcase_13 AC 85 ms
8,364 KB
testcase_14 AC 84 ms
8,364 KB
testcase_15 AC 86 ms
8,364 KB
testcase_16 AC 85 ms
8,364 KB
testcase_17 AC 84 ms
8,364 KB
testcase_18 AC 86 ms
8,364 KB
testcase_19 AC 96 ms
8,364 KB
testcase_20 AC 88 ms
8,364 KB
testcase_21 AC 85 ms
8,364 KB
testcase_22 AC 89 ms
8,364 KB
testcase_23 AC 85 ms
8,364 KB
testcase_24 AC 85 ms
8,364 KB
testcase_25 AC 84 ms
8,364 KB
testcase_26 AC 86 ms
8,364 KB
testcase_27 AC 85 ms
8,364 KB
testcase_28 AC 83 ms
8,364 KB
testcase_29 AC 84 ms
8,364 KB
testcase_30 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

struct S {
  int d;
  mint acc, t;
};

mint tsz[100010], pow_m[100010];

S op(S f, S g) {
  return S{f.d + g.d, f.acc + f.t * tsz[g.d] + g.acc, f.t * pow_m[g.d] + g.t};
}
S e() { return {0, mint(), mint()}; }

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, mi, k, q;
  cin >> n >> mi >> k >> q;
  k++;
  mint m = mi;
  pow_m[0] = 1;
  rep(i, n) pow_m[i+1] = pow_m[i] * m;
  rep(i, n) tsz[i+1] = tsz[i] + pow_m[i];
  vector<S> init(n);
  rep(i, n) {
    int a;
    cin >> a;
    init[i] = {1, mint::raw(1), mint::raw(a - 1)};
  }
  segtree<S, op, e> seg(init);
  rep(_, q) {
    int op;
    cin >> op;
    if (op == 1) {
      int l, r;
      cin >> l >> r;
      auto [d, acc, t] = seg.prod(l - 1, r);
      int h = k - d;
      mint s;
      mint coeff = mint::raw(1);
      mint mp = m;
      while (h) {
        if (h & 1) {
          s += coeff;
          coeff *= mp * (mint::raw(1) + mp);
        } else {
          coeff *= mint::raw(1) + mp;
        }
        h >>= 1;
        mp *= mp;
      }
      mint ans = acc + t * s;
      cout << ans.val() << '\n';
    } else {
      int x, y;
      cin >> x >> y;
      seg.set(x - 1, {1, mint::raw(1), mint::raw(y - 1)});
    }
  }
}
0