結果

問題 No.2568 列辞書順列列
ユーザー Preds1dentPreds1dent
提出日時 2023-12-02 17:00:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 920 bytes
コンパイル時間 3,696 ms
コンパイル使用メモリ 174,124 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 17:00:48
合計ジャッジ時間 13,355 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 WA -
testcase_02 AC 182 ms
6,548 KB
testcase_03 AC 182 ms
6,676 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 307 ms
6,676 KB
testcase_10 AC 312 ms
6,676 KB
testcase_11 AC 307 ms
6,676 KB
testcase_12 AC 321 ms
6,676 KB
testcase_13 AC 323 ms
6,676 KB
testcase_14 AC 318 ms
6,676 KB
testcase_15 AC 317 ms
6,676 KB
testcase_16 AC 321 ms
6,676 KB
testcase_17 AC 322 ms
6,676 KB
testcase_18 AC 297 ms
6,676 KB
testcase_19 AC 293 ms
6,676 KB
testcase_20 AC 294 ms
6,676 KB
testcase_21 AC 320 ms
6,676 KB
testcase_22 AC 292 ms
6,676 KB
testcase_23 AC 295 ms
6,676 KB
testcase_24 AC 296 ms
6,676 KB
testcase_25 AC 296 ms
6,676 KB
testcase_26 AC 295 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
// S_1 = ((1), (2), ..., (m))
// S_2 = ((1, 1), (1, 2), ..., (m, m))
using mint = modint998244353;
int main() {
  int n, m, q; cin >> n >> m >> q;
  vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  vector<mint> s(n + 1);
  mint t = pow_mod(m, n - 1, 998244353);
  for (int i = 0; i < n; i++) {
    s[i + 1] = (a[i] - 1) * t + s[i];
    t /= m;
  }

  for (int i = 0; i < q; i++) {
    int l, r; cin >> l >> r;
    l--;
    mint mnow = s[r] - s[l];
    mnow = mnow / pow_mod(m, n - r, 998244353);
    cout << mnow.val()  + 1<< endl;
    // for (int j = 0; j < k; j++) {
    //   ans += (a[l + j] - 1) * pow_mod(m, k - j - 1, 998244353);
    // }
    // cout << (ans + 1) % 998244353 << endl;
  }

}
0