結果

問題 No.876 Range Compress Query
ユーザー むらためむらため
提出日時 2019-09-07 08:33:39
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,518 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 66,400 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2023-09-15 12:53:30
合計ジャッジ時間 4,471 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 93 ms
4,848 KB
testcase_12 AC 77 ms
4,596 KB
testcase_13 AC 76 ms
4,812 KB
testcase_14 AC 92 ms
4,756 KB
testcase_15 AC 63 ms
5,032 KB
testcase_16 AC 88 ms
5,328 KB
testcase_17 AC 88 ms
5,376 KB
testcase_18 AC 94 ms
5,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils
template times*(n:int,body) = (for _ in 0..<n: body)
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>",discardable .}
proc scan(): int =
  while true:
    var k = getchar_unlocked()
    if k < '0' or k > '9': break
    result = 10 * result + k.ord - '0'.ord

type BinaryIndexedTree[T] = ref object
  data: seq[T]
proc newBinaryIndexedTree[T](n:int):BinaryIndexedTree[T] =
  new(result)
  result.data = newSeq[T](n)
proc len[T](self:BinaryIndexedTree[T]): int = self.data.len()
proc plus[T](self:var BinaryIndexedTree[T],i:int,val:T) =
  var i = i
  while i < self.len():
    self.data[i] += val
    i = i or (i + 1)
proc `[]`[T](self:BinaryIndexedTree[T],i:int): T =
  var i = i
  while i >= 0:
    result += self.data[i]
    i = (i and (i + 1)) - 1
proc `$`[T](self:BinaryIndexedTree[T]): string =
  result = "["
  for i in 0..<self.len.min(100): result &= $(self[i]) & ", "
  return result[0..result.len()-2] & (if self.len > 100 : " ...]" else: "]")


let n = scan()
let q = scan()
var A = newSeq[int](n+2)
var B = newSeq[int](n+2)
var bit = newBinaryIndexedTree[int](n+2)
for i in 1..n: A[i] = scan()
for i in 1..n:
  B[i] = A[i+1] - A[i]
  if B[i] != 0 : bit.plus i, 1
q.times:
  if scan() == 1:
    let (l,r,x) = (scan()-1,scan(),scan())
    if B[l] != 0: bit.plus l, -1
    B[l] += x
    if B[l] != 0: bit.plus l,  1
    if B[r] != 0: bit.plus r, -1
    B[r] += x
    if B[r] != 0: bit.plus r,  1
  else:
    let (l,r) = (scan()-1,scan()-1)
    echo bit[r]-bit[l]+1
0