結果

問題 No.2568 列辞書順列列
ユーザー Preds1dentPreds1dent
提出日時 2023-12-02 17:01:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 3,000 ms
コード長 922 bytes
コンパイル時間 3,253 ms
コンパイル使用メモリ 173,536 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 17:01:44
合計ジャッジ時間 12,988 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 183 ms
6,548 KB
testcase_03 AC 181 ms
6,548 KB
testcase_04 AC 259 ms
6,548 KB
testcase_05 AC 262 ms
6,548 KB
testcase_06 AC 262 ms
6,548 KB
testcase_07 AC 256 ms
6,548 KB
testcase_08 AC 257 ms
6,548 KB
testcase_09 AC 304 ms
6,548 KB
testcase_10 AC 304 ms
6,548 KB
testcase_11 AC 304 ms
6,676 KB
testcase_12 AC 314 ms
6,676 KB
testcase_13 AC 319 ms
6,676 KB
testcase_14 AC 318 ms
6,676 KB
testcase_15 AC 313 ms
6,676 KB
testcase_16 AC 320 ms
6,676 KB
testcase_17 AC 294 ms
6,676 KB
testcase_18 AC 294 ms
6,676 KB
testcase_19 AC 291 ms
6,676 KB
testcase_20 AC 288 ms
6,676 KB
testcase_21 AC 291 ms
6,676 KB
testcase_22 AC 293 ms
6,676 KB
testcase_23 AC 293 ms
6,676 KB
testcase_24 AC 292 ms
6,676 KB
testcase_25 AC 293 ms
6,676 KB
testcase_26 AC 290 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 + 1).val() << 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