結果
問題 | No.2650 [Cherry 6th Tune *] セイジャク |
ユーザー |
![]() |
提出日時 | 2024-02-23 23:37:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,044 ms / 2,500 ms |
コード長 | 2,462 bytes |
コンパイル時間 | 411 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 103,780 KB |
最終ジャッジ日時 | 2024-09-29 09:08:10 |
合計ジャッジ時間 | 26,213 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
import sysinput = sys.stdin.readlinefrom bisect import bisect_left,bisect_right,bisectclass LazySegmentTree:def __init__(self, size, f=lambda x, y: max(x, y), default=-1):self.size = (size - 1).bit_length()self._n = 2 ** self.sizeself.default = defaultself.data = [default] * (self._n * 2)self.lazy = [None] * (self._n * 2)self.f = fdef _get_index(self, l, r):L = (l + self._n) >> 1R = (r + self._n) >> 1lc = 0 if l & 1 else (L & -L).bit_length()rc = 0 if r & 1 else (R & -R).bit_length()for i in range(self.size):if rc <= i:yield Rif L < R and lc <= i:yield LL >>= 1R >>= 1def _propagates(self, *ids):for i in reversed(ids):v = self.lazy[i - 1]if v is None:continueself.lazy[2 * i - 1] = self.data[2 * i - 1] = vself.lazy[2 * i ] = self.data[2 * i ] = vself.lazy[i - 1] = Nonedef update(self, l, r, x): # [l,r)*ids, = self._get_index(l, r)self._propagates(*ids)L = self._n + lR = self._n + rwhile L < R:if R & 1:R -= 1self.lazy[R - 1] = self.data[R - 1] = xif L & 1:self.lazy[L - 1] = self.data[L - 1] = xL += 1L >>= 1R >>= 1for i in ids:self.data[i - 1] = self.f(self.data[2 * i - 1], self.data[2 * i])def query(self, l, r): # [l,r)self._propagates(*self._get_index(l, r))L = self._n + lR = self._n + rres = self.defaultwhile L < R:if R & 1:R -= 1res = self.f(res, self.data[R - 1])if L & 1:res = self.f(res, self.data[L - 1])L += 1L >>= 1R >>= 1return resN,A=map(int,input().split())X=list(map(int,input().split()))T=int(input())LR=[list(map(int,input().split())) for _ in range(T)]Xi = list(enumerate(X))Xi.sort(key=lambda x:x[1])X.sort()st = LazySegmentTree(N)for t,(l,r) in enumerate(LR,start=1):il = bisect_left(X,l)ir = bisect_right(X,r)st.update(il,ir,t)ans = [0]*Nfor i,(j,_) in enumerate(Xi):ans[j] = st.query(i,i+1)print(*ans,sep="\n")