結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー ikomaikoma
提出日時 2024-02-23 23:37:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,074 ms / 2,500 ms
コード長 2,462 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 103,000 KB
最終ジャッジ日時 2024-02-23 23:37:46
合計ジャッジ時間 27,749 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,332 KB
testcase_01 AC 38 ms
53,332 KB
testcase_02 AC 407 ms
85,572 KB
testcase_03 AC 281 ms
80,072 KB
testcase_04 AC 759 ms
93,776 KB
testcase_05 AC 609 ms
90,532 KB
testcase_06 AC 401 ms
84,296 KB
testcase_07 AC 648 ms
90,268 KB
testcase_08 AC 347 ms
82,328 KB
testcase_09 AC 1,069 ms
103,000 KB
testcase_10 AC 1,074 ms
102,464 KB
testcase_11 AC 1,054 ms
102,724 KB
testcase_12 AC 1,050 ms
102,984 KB
testcase_13 AC 1,028 ms
102,088 KB
testcase_14 AC 1,043 ms
102,464 KB
testcase_15 AC 1,044 ms
102,736 KB
testcase_16 AC 862 ms
102,088 KB
testcase_17 AC 854 ms
101,348 KB
testcase_18 AC 822 ms
102,088 KB
testcase_19 AC 823 ms
101,316 KB
testcase_20 AC 832 ms
101,320 KB
testcase_21 AC 830 ms
102,080 KB
testcase_22 AC 857 ms
101,952 KB
testcase_23 AC 713 ms
101,320 KB
testcase_24 AC 789 ms
101,828 KB
testcase_25 AC 734 ms
101,972 KB
testcase_26 AC 799 ms
102,344 KB
testcase_27 AC 766 ms
102,084 KB
testcase_28 AC 750 ms
101,840 KB
testcase_29 AC 720 ms
101,964 KB
testcase_30 AC 681 ms
102,592 KB
testcase_31 AC 769 ms
101,188 KB
testcase_32 AC 481 ms
92,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from bisect import bisect_left,bisect_right,bisect

class LazySegmentTree:
    def __init__(self, size, f=lambda x, y: max(x, y), default=-1):
        self.size = (size - 1).bit_length()
        self._n = 2 ** self.size
        self.default = default
        self.data = [default] * (self._n * 2)
        self.lazy = [None] * (self._n * 2)
        self.f = f

    def _get_index(self, l, r):
        L = (l + self._n) >> 1
        R = (r + self._n) >> 1
        lc = 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 R
            if L < R and lc <= i:
                yield L
            L >>= 1
            R >>= 1

    def _propagates(self, *ids):
        for i in reversed(ids):
            v = self.lazy[i - 1]
            if v is None:
                continue
            self.lazy[2 * i - 1] = self.data[2 * i - 1] = v
            self.lazy[2 * i    ] = self.data[2 * i    ] = v
            self.lazy[i - 1] = None

    def update(self, l, r, x):  # [l,r)
        *ids, = self._get_index(l, r)
        self._propagates(*ids)
        L = self._n + l
        R = self._n + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R - 1] = self.data[R - 1] = x
            if L & 1:
                self.lazy[L - 1] = self.data[L - 1] = x
                L += 1
            L >>= 1
            R >>= 1
        for 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 + l
        R = self._n + r
        res = self.default
        while L < R:
            if R & 1:
                R -= 1
                res = self.f(res, self.data[R - 1])
            if L & 1:
                res = self.f(res, self.data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return res

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)]
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]*N
for i,(j,_) in enumerate(Xi):
    ans[j] = st.query(i,i+1)
print(*ans,sep="\n")

0