結果
問題 | No.875 Range Mindex Query |
ユーザー | むらため |
提出日時 | 2019-09-06 21:54:19 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 241 ms / 2,000 ms |
コード長 | 2,464 bytes |
コンパイル時間 | 2,473 ms |
コンパイル使用メモリ | 61,272 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-07-02 16:06:24 |
合計ジャッジ時間 | 5,214 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 191 ms
6,912 KB |
testcase_12 | AC | 156 ms
5,376 KB |
testcase_13 | AC | 132 ms
6,912 KB |
testcase_14 | AC | 129 ms
6,912 KB |
testcase_15 | AC | 180 ms
6,912 KB |
testcase_16 | AC | 221 ms
6,912 KB |
testcase_17 | AC | 241 ms
6,912 KB |
testcase_18 | AC | 229 ms
6,912 KB |
ソースコード
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 import sequtils,math type ValWithIndex[T] = tuple[val:T,index:int] SegmentTreeWithIndex[T] = ref object data:seq[ValWithIndex[T]] n : int rawSize:int infinity: T cmp:proc(x,y:ValWithIndex[T]):ValWithIndex[T] proc newSegmentTree[T](size:int) : SegmentTreeWithIndex[T] = new(result) result.infinity = 1e12.T proc minimpl[T](x,y:ValWithIndex[T]): ValWithIndex[T] = if x.val <= y.val: x else: y result.cmp = minimpl result.n = size.nextPowerOfTwo() result.rawSize = size result.data = newSeqWith(result.n * 2,(result.infinity,-1)) proc `[]=`[T](self:var SegmentTreeWithIndex[T],i:int,val:T) = let baseI = i var i = i + self.n - 1 self.data[i] = (val,baseI) while i > 0: i = (i - 1) shr 1 self.data[i] = self.cmp(self.data[i * 2 + 1],self.data[i * 2 + 2]) proc queryImpl[T](self:SegmentTreeWithIndex[T],a,b,k,l,r:int) : ValWithIndex[T] = if r <= a or b <= l : return (self.infinity,-1) if a <= l and r <= b : return self.data[k] let vl = self.queryImpl(a,b,k*2+1,l,(l+r) shr 1) let vr = self.queryImpl(a,b,k*2+2,(l+r) shr 1,r) return self.cmp(vl,vr) proc `[]`[T](self:SegmentTreeWithIndex[T],slice:Slice[int]): ValWithIndex[T] = return self.queryImpl(slice.a,slice.b+1,0,0,self.n) proc `$`[T](self:SegmentTreeWithIndex[T]): string = var arrs : seq[seq[ValWithIndex[T]]] = @[] var l = 0 var r = 1 while r <= self.data.len: arrs.add self.data[l..<r] l = l * 2 + 1 r = r * 2 + 1 return $arrs let n = scan() let q = scan() var S = newSegmentTree[int](n) for i in 0..<n: S[i] = scan() q.times: let (x,l,r) = (scan(),scan()-1,scan()-1) if x == 1: var lx = S[l..l].val var rx = S[r..r].val S[l] = rx S[r] = lx else: # echo S let x = S[l..r] echo x.index + 1