結果

問題 No.876 Range Compress Query
ユーザー むらためむらため
提出日時 2019-09-06 23:03:48
言語 Nim
(2.0.0)
結果
WA  
実行時間 -
コード長 2,177 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 66,484 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-15 12:52:56
合計ジャッジ時間 4,413 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils
# import algorithm,math,tables
# import times,macros,queues,bitops,strutils,intsets,sets
# import rationals,critbits,ropes,nre,pegs,complex,stats,heapqueue,sugar
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)
# template stopwatch(body) = (let t1 = cpuTime();body;stderr.writeLine "TIME:",(cpuTime() - t1) * 1000,"ms")
# proc `^`(n:int) : int{.inline.} = (1 shl n)
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" ,discardable.}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    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()
let B = newSeqWith(n,scan())
var A = newBinaryIndexedTree[int](n+10)
var D = newBinaryIndexedTree[int](n+10)
for i in 1..<n:
  A.plus i+1, B[i] - B[i-1]
for i in 2..<n:
  if A[i] != A[i-1]: D.plus i, 1
q.times:
  let qtype = scan()
  # echo "---"
  if qtype == 1:
    let (l,r,x) = (scan(),scan(),scan())
    let dal = A[l-1] == A[l]
    let dar = A[r] == A[r+1]
    A.plus l,x
    A.plus r+1,-x
    let dal2 = A[l-1] == A[l]
    let dar2 = A[r] == A[r+1]
    if dal xor dal2:
      if dal : D.plus l,1
      else: D.plus l,-1
    if dar xor dar2:
      if dar : D.plus r+1,1
      else: D.plus r+1,-1
    # echo A
    # echo D
    # echo l," ",r," ",x
  else:
    let (l,r) = (scan(),scan())
    # echo A
    # echo D
    # echo l," ",r#," ",x
    echo D[r]-D[l]+1
0