結果

問題 No.2568 列辞書順列列
ユーザー MagentorMagentor
提出日時 2023-11-17 17:04:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 654 ms / 3,000 ms
コード長 928 bytes
コンパイル時間 6,731 ms
コンパイル使用メモリ 312,080 KB
実行使用メモリ 14,672 KB
最終ジャッジ日時 2023-11-17 17:04:38
合計ジャッジ時間 25,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 169 ms
6,676 KB
testcase_03 AC 169 ms
6,676 KB
testcase_04 AC 418 ms
14,672 KB
testcase_05 AC 421 ms
14,672 KB
testcase_06 AC 419 ms
14,672 KB
testcase_07 AC 418 ms
14,672 KB
testcase_08 AC 421 ms
14,672 KB
testcase_09 AC 404 ms
14,672 KB
testcase_10 AC 403 ms
14,672 KB
testcase_11 AC 404 ms
14,672 KB
testcase_12 AC 566 ms
14,672 KB
testcase_13 AC 565 ms
14,672 KB
testcase_14 AC 569 ms
14,672 KB
testcase_15 AC 564 ms
14,672 KB
testcase_16 AC 568 ms
14,672 KB
testcase_17 AC 643 ms
14,672 KB
testcase_18 AC 643 ms
14,672 KB
testcase_19 AC 642 ms
14,672 KB
testcase_20 AC 644 ms
14,672 KB
testcase_21 AC 645 ms
14,672 KB
testcase_22 AC 642 ms
14,672 KB
testcase_23 AC 641 ms
14,672 KB
testcase_24 AC 644 ms
14,672 KB
testcase_25 AC 654 ms
14,672 KB
testcase_26 AC 643 ms
14,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
typedef long long ll;
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;
}
long long mod=998244353LL,n,m,q;
struct S{
  ll value;
  ll length;
  
  S operator+(S other) {
  S ret;
  ret.value = (modpow(m,other.length,mod)*value+other.value)%mod;
  ret.length = length+other.length;
  return ret;
  }
  
  ll val(){
    return value % mod;
  }
};
S op(S a,S b){
  return a+b;
}
S e(){
  return {0LL,0LL};
}
int main() {
  cin >> n >> m >> q;
  vector<S> v(n);
  for(int i = 0;i < n;i++){
    ll a;cin>>a;a--;
    v[i].value = a;v[i].length = 1; 
  }
 segtree<S,op,e> seg(v);
 for(int i = 0;i < q;i++){
   ll l,r;cin>>l>>r;l--;
   cout << (seg.prod(l,r).val()+1)%mod << endl;
 }
}
0