結果

問題 No.2571 列辞書順列
ユーザー momoyuumomoyuu
提出日時 2023-12-15 15:29:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 3,000 ms
コード長 1,219 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 109,016 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-15 15:29:47
合計ジャッジ時間 10,319 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 109 ms
6,548 KB
testcase_03 AC 109 ms
6,548 KB
testcase_04 AC 181 ms
6,548 KB
testcase_05 AC 180 ms
6,548 KB
testcase_06 AC 212 ms
6,548 KB
testcase_07 AC 215 ms
6,676 KB
testcase_08 AC 100 ms
6,676 KB
testcase_09 AC 100 ms
6,676 KB
testcase_10 AC 164 ms
6,676 KB
testcase_11 AC 162 ms
6,676 KB
testcase_12 AC 161 ms
6,676 KB
testcase_13 AC 161 ms
6,676 KB
testcase_14 AC 162 ms
6,676 KB
testcase_15 AC 160 ms
6,676 KB
testcase_16 AC 164 ms
6,676 KB
testcase_17 AC 161 ms
6,676 KB
testcase_18 AC 161 ms
6,676 KB
testcase_19 AC 161 ms
6,676 KB
testcase_20 AC 160 ms
6,676 KB
testcase_21 AC 161 ms
6,676 KB
testcase_22 AC 163 ms
6,676 KB
testcase_23 AC 160 ms
6,676 KB
testcase_24 AC 162 ms
6,676 KB
testcase_25 AC 162 ms
6,676 KB
testcase_26 AC 161 ms
6,676 KB
testcase_27 AC 161 ms
6,676 KB
testcase_28 AC 163 ms
6,676 KB
testcase_29 AC 162 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

#include<atcoder/modint>
using mint = atcoder::modint998244353;

#include<atcoder/fenwicktree>
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n,m,k,q;
    cin>>n>>m>>k>>q;
    vector<ll> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];

    atcoder::fenwick_tree<mint> b1(n),b2(n);
    for(int i = 0;i<n;i++){
        b1.add(i,a[i]-1);
        if(m!=1) b2.add(i,mint(a[i]-1)*(mint(m).pow(k-i)));
    }
    for(int i = 0;i<q;i++){
        int op;
        cin>>op;
        if(op==1){
            mint ans = 0;
            int l,r;
            cin>>l>>r;
            l--;
            if(m!=1){
                ans += b2.sum(l,r)*(mint(m).pow(l));
                ans -= b1.sum(l,r);
                ans /= m - 1;
            }
            ans += r - l;
            cout<<ans.val()<<endl;
        }else{
            ll i,x;
            cin>>i>>x;
            i--;
            b1.add(i,-(a[i]-1));
            if(m!=1) b2.add(i,-(mint(a[i]-1)*(mint(m).pow(k-i))));
            a[i] = x;
            b1.add(i,a[i]-1);
            if(m!=1) b2.add(i,mint(a[i]-1)*(mint(m).pow(k-i)));
        }
    }

}
0