結果
問題 | No.2650 [Cherry 6th Tune *] セイジャク |
ユーザー | FromBooska |
提出日時 | 2024-02-24 06:40:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,236 ms / 2,500 ms |
コード長 | 3,281 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 82,216 KB |
実行使用メモリ | 97,912 KB |
最終ジャッジ日時 | 2024-09-29 09:52:48 |
合計ジャッジ時間 | 28,889 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,972 KB |
testcase_01 | AC | 39 ms
53,092 KB |
testcase_02 | AC | 493 ms
85,744 KB |
testcase_03 | AC | 321 ms
79,956 KB |
testcase_04 | AC | 832 ms
88,344 KB |
testcase_05 | AC | 690 ms
86,268 KB |
testcase_06 | AC | 473 ms
82,536 KB |
testcase_07 | AC | 733 ms
86,408 KB |
testcase_08 | AC | 390 ms
81,184 KB |
testcase_09 | AC | 1,230 ms
97,272 KB |
testcase_10 | AC | 1,190 ms
96,920 KB |
testcase_11 | AC | 1,209 ms
97,912 KB |
testcase_12 | AC | 1,229 ms
97,372 KB |
testcase_13 | AC | 1,236 ms
97,000 KB |
testcase_14 | AC | 1,217 ms
97,900 KB |
testcase_15 | AC | 1,221 ms
97,500 KB |
testcase_16 | AC | 812 ms
95,864 KB |
testcase_17 | AC | 817 ms
95,600 KB |
testcase_18 | AC | 832 ms
95,728 KB |
testcase_19 | AC | 834 ms
95,748 KB |
testcase_20 | AC | 819 ms
96,240 KB |
testcase_21 | AC | 834 ms
95,036 KB |
testcase_22 | AC | 816 ms
95,212 KB |
testcase_23 | AC | 767 ms
95,672 KB |
testcase_24 | AC | 809 ms
95,828 KB |
testcase_25 | AC | 795 ms
96,372 KB |
testcase_26 | AC | 813 ms
95,256 KB |
testcase_27 | AC | 797 ms
96,464 KB |
testcase_28 | AC | 783 ms
96,000 KB |
testcase_29 | AC | 772 ms
95,972 KB |
testcase_30 | AC | 651 ms
95,500 KB |
testcase_31 | AC | 974 ms
95,108 KB |
testcase_32 | AC | 617 ms
90,772 KB |
ソースコード
# Xは入力時に昇順とは限らない # 遅延セグメントツリーのrange update queryバージョン # https://qiita.com/ether2420/items/7b67b2b35ad5f441d686 def segfunc(x,y): return max(x, y) class LazySegTree_RUQ: def __init__(self,init_val,segfunc,ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1<<(n-1).bit_length() self.tree = [ide_ele]*2*self.num self.lazy = [None]*2*self.num for i in range(n): self.tree[self.num+i] = init_val[i] for i in range(self.num-1,0,-1): self.tree[i] = self.segfunc(self.tree[2*i],self.tree[2*i+1]) def gindex(self,l,r): l += self.num r += self.num lm = l>>(l&-l).bit_length() rm = r>>(r&-r).bit_length() while r>l: if l<=lm: yield l if r<=rm: yield r r >>= 1 l >>= 1 while l: yield l l >>= 1 def propagates(self,*ids): for i in reversed(ids): v = self.lazy[i] if v is None: continue self.lazy[i] = None self.lazy[2*i] = v self.lazy[2*i+1] = v self.tree[2*i] = v self.tree[2*i+1] = v def update(self,l,r,x): ids = self.gindex(l,r) self.propagates(*self.gindex(l,r)) l += self.num r += self.num while l<r: if l&1: self.lazy[l] = x self.tree[l] = x l += 1 if r&1: self.lazy[r-1] = x self.tree[r-1] = x r >>= 1 l >>= 1 for i in ids: self.tree[i] = self.segfunc(self.tree[2*i], self.tree[2*i+1]) def query(self,l,r): ids = self.gindex(l,r) self.propagates(*self.gindex(l,r)) res = self.ide_ele l += self.num r += self.num while l<r: if l&1: res = self.segfunc(res,self.tree[l]) l += 1 if r&1: res = self.segfunc(res,self.tree[r-1]) l >>= 1 r >>= 1 return res N, A = map(int, input().split()) X = list(map(int, input().split())) T = int(input()) LR = [] for i in range(T): l, r = map(int, input().split()) LR.append((l, r)) X_idx = [] for i in range(N): X_idx.append((X[i], i)) X_idx.sort() X_sorted = sorted(X) X_min = X_sorted[0] X_max = X_sorted[-1] from bisect import bisect_left, bisect_right hear = [-1]*N LSTRU = LazySegTree_RUQ(hear, segfunc, -1) for i in range(T): l, r = LR[i] if l > X_max or r < X_min: continue l_idx = bisect_left(X_sorted, l) r_idx = bisect_left(X_sorted, r+1) #print('i', i, 'l_idx', l_idx, 'r_idx', r_idx) # 中間に落ちてしまうケースがある if l_idx < r_idx and l_idx < N and r_idx >= 1: LSTRU.update(l_idx,r_idx,i+1) #temp = [] #for i in range(N): # calc = LSTRU.query(i, i+1) # temp.append(calc) #print(temp) ans_list = [-1]*N for i in range(N): calc = LSTRU.query(i, i+1) ans_list[X_idx[i][1]] = calc for a in ans_list: print(a)