結果
| 問題 | No.789 範囲の合計 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-02-11 05:06:25 | 
| 言語 | Nim (2.2.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,555 bytes | 
| コンパイル時間 | 2,749 ms | 
| コンパイル使用メモリ | 62,640 KB | 
| 実行使用メモリ | 13,696 KB | 
| 最終ジャッジ日時 | 2024-07-01 19:20:48 | 
| 合計ジャッジ時間 | 5,527 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 2 TLE * 1 -- * 12 | 
ソースコード
import sequtils,algorithm
setStdIoUnbuffered()
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
template useBinaryIndexedTree() = # 部分和検索 / 更新 O(log(N))
  type BinaryIndexedTree[T] = ref object
    data: seq[T] # 引数以下の部分和(Fenwick Tree)
  proc initBinaryIndexedTree[T](n:int):BinaryIndexedTree[T] =
    new(result)
    result.data = newSeq[T](n)
  proc len[T](self:BinaryIndexedTree[T]): int = self.data.len()
  proc update[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: "]")
useBinaryIndexedTree()
let n = scan()
let Q = newSeqWith(n,(q:scan(),x:scan(),y:scan()))
var V = newSeq[int]()
for q in Q:
  V &= q.x
  if q.q == 1: V &= q.y
V = V.sorted(cmp).deduplicate()
var bit = initBinaryIndexedTree[int](V.len + 1)
var ans = 0
for q in Q:
  let x = V.lowerBound(q.x)
  if q.q == 0: bit.update(x,q.y)
  else:
    let y = V.lowerBound(q.y)
    if x == 0: ans += bit[y]
    else: ans += bit[y] - bit[x-1]
echo ans
            
            
            
        