結果

問題 No.876 Range Compress Query
ユーザー 6soukiti296soukiti29
提出日時 2019-09-06 22:17:03
言語 Nim
(2.0.0)
結果
WA  
実行時間 -
コード長 1,358 bytes
コンパイル時間 3,206 ms
コンパイル使用メモリ 68,668 KB
実行使用メモリ 15,084 KB
最終ジャッジ日時 2023-09-15 12:52:23
合計ジャッジ時間 5,855 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,560 KB
testcase_01 WA -
testcase_02 AC 3 ms
4,788 KB
testcase_03 WA -
testcase_04 AC 3 ms
4,648 KB
testcase_05 AC 3 ms
4,676 KB
testcase_06 AC 5 ms
4,644 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 189 ms
13,100 KB
testcase_12 AC 156 ms
12,856 KB
testcase_13 AC 154 ms
13,028 KB
testcase_14 AC 185 ms
13,092 KB
testcase_15 AC 131 ms
13,756 KB
testcase_16 AC 181 ms
15,084 KB
testcase_17 AC 180 ms
14,976 KB
testcase_18 AC 192 ms
14,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,strutils
type
    binaryIndexTree[I:static[int]] = array[I + 1,int64] 

proc add(BIT :var binaryIndexTree,i : int64, a : int64)=
    var index = i
    while BIT[0] >= index:
        BIT[index] += a
        index += ((index xor (index - 1)) and index)

proc sum(BIT : binaryIndexTree, i : int64):int64 =
    var index = i
    while index > 0:
        result += BIT[index]
        index = (index and (index - 1))

proc initBit(i : static[int]) : binaryIndexTree[i] =
    var res : binaryIndexTree[i]
    res[0] = i
    return res

var
    N, Q : int64
(N, Q) = stdin.readline.split.map(parseBiggestInt)
var
    BIT = initBit(100010)
    A = stdin.readline.split.map(parseBiggestInt)
    S : array[100010, int64]

for i, a in A:
    if i == 0:
        continue
    S[i] = a - A[i - 1]
    if S[i] != 0:
        BIT.add(i, 1)

for q in 1..Q:
    var L = stdin.readline.split.map(parseBiggestInt)
    var
        l = L[1]
        r = L[2]
    if L[0] == 1:
        var x = L[3]
        S[l - 1] += x
        S[r] -= x
        if l > 2 and S[l - 1] == S[l - 2]:
            BIT.add(l - 1, -1)
        elif l > 2 and S[l - 1] - S[l - 2] == x:
            BIT.add(l - 1, 1)
        if S[r] == S[r - 1]:
            BIT.add(r, -1)
        elif S[r] - S[r - 1] == -x:
            BIT.add(r, 1)
    else:
        echo BIT.sum(r - 1) - BIT.sum(l - 1) + 1
0