結果

問題 No.2568 列辞書順列列
ユーザー GOTKAKOGOTKAKO
提出日時 2023-12-02 15:52:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 3,000 ms
コード長 755 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 204,844 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2023-12-02 15:53:04
合計ジャッジ時間 9,170 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 127 ms
6,676 KB
testcase_03 AC 127 ms
6,676 KB
testcase_04 AC 154 ms
8,064 KB
testcase_05 AC 154 ms
8,064 KB
testcase_06 AC 155 ms
8,064 KB
testcase_07 AC 156 ms
8,064 KB
testcase_08 AC 155 ms
8,064 KB
testcase_09 AC 195 ms
8,064 KB
testcase_10 AC 172 ms
8,064 KB
testcase_11 AC 168 ms
8,064 KB
testcase_12 AC 170 ms
8,064 KB
testcase_13 AC 174 ms
8,064 KB
testcase_14 AC 176 ms
8,064 KB
testcase_15 AC 196 ms
8,064 KB
testcase_16 AC 173 ms
8,064 KB
testcase_17 AC 165 ms
8,064 KB
testcase_18 AC 164 ms
8,064 KB
testcase_19 AC 167 ms
8,064 KB
testcase_20 AC 171 ms
8,064 KB
testcase_21 AC 185 ms
8,064 KB
testcase_22 AC 171 ms
8,064 KB
testcase_23 AC 162 ms
8,064 KB
testcase_24 AC 162 ms
8,064 KB
testcase_25 AC 166 ms
8,064 KB
testcase_26 AC 169 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long mod = 998244353;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M,Q; cin >> N >> M >> Q;
    vector<long long> A(N);
    for(auto &a : A) cin >> a,a--;

    vector<long long> L1(N);
    long long now = 0;
    for(int i=0; i<N; i++){
        now = now*M%mod;
        now = (now+A.at(i))%mod;
        L1.at(i) = now;
    }

    vector<long long> powerM(N+1,1);
    for(int i=1; i<=N; i++) powerM.at(i) = powerM.at(i-1)*M%mod;

    for(int i=0; i<Q; i++){
        int l,r; cin >> l >> r;
        l--; r--;

        long long answer = L1.at(r);
        if(l) answer = (answer-L1.at(l-1)*powerM.at(r-l+1)%mod+mod)%mod;
        cout << (answer+1)%mod << endl;
    }
}
0