結果

問題 No.2568 列辞書順列列
ユーザー chaemonchaemon
提出日時 2023-12-02 16:26:46
言語 Nim
(2.0.2)
結果
AC  
実行時間 265 ms / 3,000 ms
コード長 20,031 bytes
コンパイル時間 4,502 ms
コンパイル使用メモリ 96,384 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-26 20:18:57
合計ジャッジ時間 12,530 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 146 ms
5,376 KB
testcase_03 AC 146 ms
5,376 KB
testcase_04 AC 201 ms
6,784 KB
testcase_05 AC 197 ms
6,912 KB
testcase_06 AC 196 ms
6,784 KB
testcase_07 AC 200 ms
6,940 KB
testcase_08 AC 199 ms
6,912 KB
testcase_09 AC 255 ms
6,912 KB
testcase_10 AC 260 ms
6,912 KB
testcase_11 AC 252 ms
6,948 KB
testcase_12 AC 262 ms
6,940 KB
testcase_13 AC 265 ms
6,784 KB
testcase_14 AC 257 ms
6,912 KB
testcase_15 AC 262 ms
6,912 KB
testcase_16 AC 257 ms
6,784 KB
testcase_17 AC 238 ms
6,912 KB
testcase_18 AC 240 ms
6,912 KB
testcase_19 AC 242 ms
6,784 KB
testcase_20 AC 238 ms
6,948 KB
testcase_21 AC 242 ms
6,944 KB
testcase_22 AC 243 ms
6,784 KB
testcase_23 AC 234 ms
6,912 KB
testcase_24 AC 238 ms
6,784 KB
testcase_25 AC 236 ms
6,784 KB
testcase_26 AC 241 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import macros
macro Please(x): untyped = nnkStmtList.newTree()

Please use Nim-ACL
Please use Nim-ACL
Please use Nim-ACL


static:
  when not defined SecondCompile:
    # md5sum: c7ae4897b944034f7609709966308055  atcoder.tar.xz

    template getFileName():string = instantiationInfo().filename
    let fn = getFileName()
    block:
      let (output, ex) = gorgeEx("if [ -e ./atcoder ]; then exit 1; else exit 0; fi")
      # doAssert ex == 0, "atcoder directory already exisits"
    discard staticExec("echo \"/Td6WFoAAATm1rRGAgAhARwAAAAQz1jM4Rf/NaNdADCdCIqmAHyeLmzPetXzWpgQcDgKgJF+nO8CaeoEXtWIJ5QVhEjd2K9HJwLRxgm83A8MMvxuqFqAOWu1LQtQ0Ne0DeJkYob9XJpOXS///B6msKcXT386nWjzweTLdl30wwMey+7/w9d3CNFIH7AbUy1QAYtSALKvqohcejJIDrZMtJ1BTDblbWbpDgqjGQaTDilZTry6Ow+93JRlMNFFQxLpd11N5QvLuPdtb9OLWArFOY94kSlQyBo1hgQ0j93ioiIIEXfTKgaULMaTekrAupIUjA8OVJTLg4bXYl0PRyzbj2lsNg3wdSX320nsgzNjCbkUvi+PgGZ9D9m5qH8ym09rQIRZFEsVZYmZTvktTW/W9uaSpBqN3g1PGuTHiXd7hqMVw+zE5TFOLi3ey3gJ6/e6X0rw9vBvNjQ+5SKXonG83AoZjNnBwo5N6vN5k9m/Zh5jnt4GKzlu4/EZppFjPhuhBFsV4F3ZALzNolmxPNGDLZ4kUW7oDRA0hX1WMX7Qfemnsr8FMrGhWgt5jSRUc95niYUKh6pWjIKUZ1eomVPVgUw4NBOUwP8MVjxTRdo8Bh1O+GczaIXbRq+j+trGS62g7259MGLTm9vG5/IeiAI3Ul2gjPNnlNePs8mRzryRMT/SeU/thSpvBjVpBy0yPbxV5Kjm3i/A7x/X+iiH6M4emGB75JuDoWq36IXxHtDcYBmv82ocoLwGDOxJ6XR7GjwY1pbaC586H11Yvbiu2bIEG2E35g8aQ/VHh2GjM2P6UnhudwczUE6+/YMBHJoewCZcoZWjS3RIDX2pwY1ZgPTxkaK8okX/8SU0hvsizg2fvdGIpYzTqbY4kqN8mcKM09R2aKQWjJljSNLb1dzM39qBTPCs9AmLdrpA9o1dH29dZveP8tlJKKvEZu+AQmXHcer9BuDtB7xDcYaDou2HaFglo67gt0MmaQc3Kh4gC1+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Z9JX5+7PXUTfq0ZHLDdtDiJLcWs3B1XLQBTi0UpFphaeT/MJyKElqKtOVKQ4Jb3XR4SbBNwDi3H4J6mLI5pa3+EIz3wKB0JA5N/BFEw0sOpTNZL7VNXAAAMnFTRjz8Yw0AAb9rgLAEAA6+QIqxxGf7AgAAAAAEWVo=\" | base64 -d > atcoder.tar.xz && tar -Jxvf atcoder.tar.xz")
    let (output, ex) = gorgeEx("nim cpp -d:release -d:SecondCompile -d:danger --path:./ --opt:speed --multimethods:on --warning[SmallLshouldNotBeUsed]:off --checks:off -o:a.out " & fn)
    discard staticExec("rm -rf ./atcoder");doAssert ex == 0, output;quit(0)


when defined SecondCompile:
  const DO_CHECK = false;const DEBUG = false
else:
  const DO_CHECK = true;const DEBUG = true
const
  USE_DEFAULT_TABLE = true
  DO_TEST = false

# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/extra/header/chaemon_header.nim
include atcoder/extra/header/chaemon_header

# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/modint.nim
import atcoder/modint

type mint = modint998244353

proc solve() =
  let N, M, Q = nextInt()
  var A = Seq[N: nextInt()]
  for i in N: A[i].dec
  var
    a = Seq[N: mint]
    p = mint(1)
  for i in 0 ..< N << 1:
    a[i] = p * A[i]
    p *= M
  var cs = mint(0) & a.cumsummed
  for _ in Q:
    var l, r = nextInt()
    l.dec
    # l ..< r
    echo (cs[r] - cs[l]) * mint(M).inv()^(N - r) + 1


solve()

0