結果
問題 | No.318 学学学学学 |
ユーザー |
|
提出日時 | 2020-09-06 21:45:21 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 280 ms / 2,000 ms |
コード長 | 3,245 bytes |
コンパイル時間 | 5,516 ms |
コンパイル使用メモリ | 75,392 KB |
実行使用メモリ | 31,360 KB |
最終ジャッジ日時 | 2024-11-29 07:39:58 |
合計ジャッジ時間 | 10,757 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 38) Warning: imported and not used: 'math' [UnusedImport] /home/judge/data/code/Main.nim(1, 70) Warning: imported and not used: 'sugar' [UnusedImport]
ソースコード
import algorithm, deques, heapqueue, math, sets, sequtils, strutils, sugar, tablesproc input*(): string =return stdin.readLineproc chmax*[T: SomeNumber](num0: var T, num1: T) =num0 = max(num0, num1)proc chmin*[T: SomeNumber](num0: var T, num1: T) =num0 = min(num0, num1)proc bit_length(n: Natural): Natural =if n == 0:return 0let s = toBin(n, 60)return 60 - s.find('1')typeDuelSegmentTree*[T] = ref objectLV: NaturalN0: Positivelazy_ide_ele: Tlazy_data: seq[T]proc initDuelSegmentTree*[T](size: Positive, lazy_ide_ele: T): DuelSegmentTree[T] =varLV = bit_length(size - 1)N0 = 1 shl LVreturn DuelSegmentTree[T](LV: LV, N0: N0, lazy_ide_ele: lazy_ide_ele, lazy_data: newSeqWith(2 * N0, lazy_ide_ele))iterator gindex*[T](self: var DuelSegmentTree[T], left, right: Natural): Natural =varL = (left + self.N0) shr 1R = (right + self.N0) shr 1lc = if (left and 1) == 1: 0 else: bit_length(L and -L)rc = if (right and 1) == 1: 0 else: bit_length(R and -R)for i in 0..<self.LV:if rc <= i:yield Rif L < R and lc <= i:yield LL = L shr 1R = R shr 1proc propagates*[T](self: var DuelSegmentTree[T], ids: seq[Natural]) =varidx: Naturalv: Tfor id in reversed(ids):idx = id - 1v = self.lazy_data[idx]if v == self.lazy_ide_ele:continueself.lazy_data[2*idx + 1] = vself.lazy_data[2*idx + 2] = vself.lazy_data[idx] = self.lazy_ide_eleproc update*[T](self: var DuelSegmentTree[T], left, right: Natural, x: T) =self.propagates(toSeq(self.gindex(left, right)))varL = left + self.N0R = right + self.N0while L < R:if (L and 1) == 1:self.lazy_data[L - 1] = xinc Lif (R and 1) == 1:dec Rself.lazy_data[R - 1] = xL = L shr 1R = R shr 1proc query*[T](self: var DuelSegmentTree[T], k: Natural): T =self.propagates(toSeq(self.gindex(k, k + 1)))return self.lazy_data[k + self.N0 - 1]vara, sorted_a, a_left, a_right, ans: seq[int]a_set: HashSet[int]compress: Table[int, int]duel_seg_tree: DuelSegmentTree[int]proc solve() =let n = input().parseInta = input().split.map(parseInt)a_set = toHashSet(a)sorted_a = sorted(toSeq(a_set.items))compress = initTable[int, int]()for idx, val in sorted_a:compress[val] = idx(a_left, a_right) = (newSeqWith(compress.len, -1), newSeqWith(compress.len, -1))for i, ai in a:if a_left[compress[ai]] == -1:a_left[compress[ai]] = ielse:a_right[compress[ai]] = iduel_seg_tree = initDuelSegmentTree(n, 0)for i, ai in sorted_a:if a_right[i] != -1:duel_seg_tree.update(a_left[i], a_right[i] + 1, ai)else:duel_seg_tree.update(a_left[i], a_left[i] + 1, ai)ans = newSeq[int](n)for i in 0..<n:ans[i] = duel_seg_tree.query(i)echo ans.join(" ")when is_main_module:solve()