結果

問題 No.2611 Count 01
ユーザー MitarushiMitarushi
提出日時 2024-01-07 11:05:00
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,153 bytes
コンパイル時間 3,012 ms
コンパイル使用メモリ 66,380 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-19 19:08:41
合計ジャッジ時間 4,359 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils, deques

type stdinReader = object
    buf: Deque[string]

func newStdinReader(): stdinReader =
    result = stdinReader(buf: initDeque[string]())

proc readString(sr: var stdinReader): string =
    if sr.buf.len == 0:
        sr.buf = stdin.readLine.split.toDeque
    sr.buf.popFirst

proc readInt(sr: var stdinReader): int =
    readString(sr).parseInt

var reader = newStdinReader()
let (n, q) = (reader.readInt, reader.readInt)
let s = reader.readString
var sSeq = s.mapIt(int(it) - int('0'))

const MOD = 998244353

if q > 10000:
    quit(0)

for _ in 0..<q:
    let t = reader.readInt
    if t == 1:
        let i = reader.readInt - 1
        sSeq[i] = 1 - sSeq[i]
    else:
        let (l, r) = (reader.readInt - 1, reader.readInt)
        var cumsum = newSeq[int](r - l + 1)
        cumsum[0] = 0
        for i, x in sSeq[l..<r]:
            cumsum[i + 1] = cumsum[i] + x
        
        var ans = 0
        for i in 0..<cumsum.len:
            for j in i+1..<cumsum.len:
                let len = j - i
                let x = cumsum[j] - cumsum[i]
                ans = (ans + x * (len - x)) mod MOD
        echo ans
0