結果
問題 | No.876 Range Compress Query |
ユーザー | 6soukiti29 |
提出日時 | 2019-09-06 22:13:59 |
言語 | Nim (2.0.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,323 bytes |
コンパイル時間 | 3,058 ms |
コンパイル使用メモリ | 68,688 KB |
実行使用メモリ | 15,220 KB |
最終ジャッジ日時 | 2023-09-15 12:52:17 |
合計ジャッジ時間 | 5,810 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,532 KB |
testcase_01 | WA | - |
testcase_02 | AC | 3 ms
4,656 KB |
testcase_03 | WA | - |
testcase_04 | AC | 3 ms
4,776 KB |
testcase_05 | AC | 3 ms
4,624 KB |
testcase_06 | AC | 4 ms
4,588 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 186 ms
13,236 KB |
testcase_12 | AC | 159 ms
13,016 KB |
testcase_13 | AC | 156 ms
13,196 KB |
testcase_14 | AC | 185 ms
13,164 KB |
testcase_15 | AC | 131 ms
13,932 KB |
testcase_16 | AC | 178 ms
15,220 KB |
testcase_17 | AC | 177 ms
15,032 KB |
testcase_18 | AC | 190 ms
15,144 KB |
ソースコード
import sequtils,strutils type binaryIndexTree[I:static[int]] = array[I + 1,int] proc add(BIT :var binaryIndexTree,i : int, a : int)= var index = i while BIT[0] >= index: BIT[index] += a index += ((index xor (index - 1)) and index) proc sum(BIT : binaryIndexTree, i : int):int = 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 : int (N, Q) = stdin.readline.split.map(parseInt) var BIT = initBit(100010) A = stdin.readline.split.map(parseInt) S : array[100010, int] 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(parseInt) 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