結果
問題 | No.2650 [Cherry 6th Tune *] セイジャク |
ユーザー | miya145592 |
提出日時 | 2024-02-23 23:09:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,315 ms / 2,500 ms |
コード長 | 2,830 bytes |
コンパイル時間 | 396 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 101,520 KB |
最終ジャッジ日時 | 2024-09-29 08:34:25 |
合計ジャッジ時間 | 30,061 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,992 KB |
testcase_01 | AC | 39 ms
52,864 KB |
testcase_02 | AC | 485 ms
85,124 KB |
testcase_03 | AC | 331 ms
81,752 KB |
testcase_04 | AC | 890 ms
94,832 KB |
testcase_05 | AC | 726 ms
90,928 KB |
testcase_06 | AC | 471 ms
84,836 KB |
testcase_07 | AC | 756 ms
90,424 KB |
testcase_08 | AC | 406 ms
83,132 KB |
testcase_09 | AC | 1,314 ms
101,372 KB |
testcase_10 | AC | 1,270 ms
101,064 KB |
testcase_11 | AC | 1,274 ms
101,520 KB |
testcase_12 | AC | 1,303 ms
101,100 KB |
testcase_13 | AC | 1,299 ms
101,324 KB |
testcase_14 | AC | 1,315 ms
100,956 KB |
testcase_15 | AC | 1,304 ms
101,356 KB |
testcase_16 | AC | 871 ms
99,804 KB |
testcase_17 | AC | 873 ms
99,724 KB |
testcase_18 | AC | 885 ms
99,784 KB |
testcase_19 | AC | 878 ms
99,812 KB |
testcase_20 | AC | 885 ms
99,812 KB |
testcase_21 | AC | 896 ms
99,548 KB |
testcase_22 | AC | 843 ms
100,196 KB |
testcase_23 | AC | 772 ms
100,072 KB |
testcase_24 | AC | 809 ms
99,684 KB |
testcase_25 | AC | 793 ms
99,692 KB |
testcase_26 | AC | 799 ms
99,660 KB |
testcase_27 | AC | 788 ms
100,188 KB |
testcase_28 | AC | 775 ms
99,812 KB |
testcase_29 | AC | 769 ms
100,060 KB |
testcase_30 | AC | 690 ms
98,756 KB |
testcase_31 | AC | 972 ms
99,800 KB |
testcase_32 | AC | 626 ms
90,052 KB |
ソースコード
# 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): if l==r: return 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 import bisect import sys input = sys.stdin.readline N, A = map(int, input().split()) X = list(map(int, input().split())) T = int(input()) LR = [list(map(int, input().split())) for _ in range(T)] for i in range(N): x = X[i] X[i] = (x, i) X.sort() ST = LazySegTree_RUQ([0 for _ in range(N)], segfunc, 0) for t in range(T): l, r = LR[t] l_pos = bisect.bisect_left(X, (l, 0)) r_pos = bisect.bisect_left(X, (r, N)) ST.update(l_pos, r_pos, t+1) ans = [-1 for _ in range(N)] for i in range(N): tmp = ST.query(i, i+1) x, idx = X[i] if tmp==0: ans[idx] = -1 else: ans[idx] = tmp for a in ans: print(a)