結果

問題 No.2568 列辞書順列列
ユーザー umezoumezo
提出日時 2023-12-02 16:51:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 3,000 ms
コード長 801 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 204,204 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2023-12-02 16:51:40
合計ジャッジ時間 5,718 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,548 KB
testcase_01 AC 3 ms
6,548 KB
testcase_02 AC 34 ms
6,548 KB
testcase_03 AC 34 ms
6,676 KB
testcase_04 AC 48 ms
8,064 KB
testcase_05 AC 51 ms
8,064 KB
testcase_06 AC 50 ms
8,064 KB
testcase_07 AC 48 ms
8,064 KB
testcase_08 AC 50 ms
8,064 KB
testcase_09 AC 62 ms
8,064 KB
testcase_10 AC 61 ms
8,064 KB
testcase_11 AC 59 ms
8,064 KB
testcase_12 AC 63 ms
8,064 KB
testcase_13 AC 61 ms
8,064 KB
testcase_14 AC 60 ms
8,064 KB
testcase_15 AC 63 ms
8,064 KB
testcase_16 AC 63 ms
8,064 KB
testcase_17 AC 60 ms
8,064 KB
testcase_18 AC 63 ms
8,064 KB
testcase_19 AC 59 ms
8,064 KB
testcase_20 AC 60 ms
8,064 KB
testcase_21 AC 58 ms
8,064 KB
testcase_22 AC 61 ms
8,064 KB
testcase_23 AC 59 ms
8,064 KB
testcase_24 AC 57 ms
8,064 KB
testcase_25 AC 59 ms
8,064 KB
testcase_26 AC 61 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=998244353;
ll modpow(ll x,ll n){
  x%=MOD;
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m,q;
  cin>>n>>m>>q;
  
  vector<ll> B(200200);
  B[0]=1;
  for(int i=1;i<200200;i++) B[i]=B[i-1]*m%MOD;
  
  vector<ll> A(n);
  rep(i,n){
    cin>>A[i];
    A[i]--;
  }
  vector<ll> S(n+1);
  ll t=1;
  for(int i=n-1;i>=0;i--){
    S[i]=(S[i+1]+A[i]*t%MOD)%MOD;
    t=t*m%MOD;
  }
  while(q--){
    int l,r;
    cin>>l>>r;
    l--;
    cout<<((S[l]-S[r]+MOD)%MOD*modpow(B[n-r],MOD-2)%MOD+1)%MOD<<'\n';
  }
  return 0;
}
0