結果
| 問題 | No.2568 列辞書順列列 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-12-02 15:52:55 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 200 ms / 3,000 ms | 
| コード長 | 755 bytes | 
| コンパイル時間 | 1,914 ms | 
| コンパイル使用メモリ | 196,784 KB | 
| 最終ジャッジ日時 | 2025-02-18 05:00:35 | 
| ジャッジサーバーID (参考情報) | judge4 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 25 | 
ソースコード
#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;
    }
}
            
            
            
        