結果

問題 No.2571 列辞書順列
ユーザー MagentorMagentor
提出日時 2023-11-26 12:13:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,593 bytes
コンパイル時間 5,669 ms
コンパイル使用メモリ 313,300 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-09 18:08:25
合計ジャッジ時間 13,349 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 251 ms
6,676 KB
testcase_05 AC 248 ms
6,676 KB
testcase_06 AC 293 ms
6,676 KB
testcase_07 AC 298 ms
6,676 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i < (long long)(n); i++)
typedef long long ll;
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()
#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
using mint = modint;
const int MOD = 998244353LL;
const ll INF = 999999999999LL;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
template <typename T>
void input(vector<T> &v){
 rep(i,v.size()){cin>>v[i];}
  return;
}
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll POW(ll a,ll n){
  long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}
int main() {
  ll n,m,k,q;cin>>n>>m>>k>>q;
  fenwick_tree<mint> fw(n);
  fenwick_tree<mint> fw2(n);
  rep(i,n){ll a;cin>>a;a--;
    mint ret = a;
    ret *= modpow(m,n-i-1,998244353LL);
    fw.add(i,ret);
    fw2.add(i,(mint)(a));
  }
  rep(i,q){
    int t;cin>>t;
    if(t==1){
      mint ans = 0;
      ll l,r;cin>>l>>r;l--;r--;
      ans += fw.sum(l,r+1);
      ans *= modpow(m,k-n+l+1,998244353LL);
      ans -= fw2.sum(l,r+1);
      ans /= m-1;
      ans += r-l+1;
      cout << ans.val() << endl;
    }
    else{
      ll x,y;cin>>x>>y;x--;y--;
      fw.add(x,-fw.sum(x,x+1));
      mint ret = y;
      y *= modpow(m,n-x-1,998244353LL);
      fw.add(x,y);
    }
  }
}
0