結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー mkawa2mkawa2
提出日時 2024-02-23 21:56:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 676 ms / 2,500 ms
コード長 2,781 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 163,584 KB
最終ジャッジ日時 2024-02-23 21:56:48
合計ジャッジ時間 18,622 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 229 ms
98,828 KB
testcase_03 AC 205 ms
89,104 KB
testcase_04 AC 501 ms
145,244 KB
testcase_05 AC 397 ms
126,740 KB
testcase_06 AC 292 ms
102,372 KB
testcase_07 AC 429 ms
133,376 KB
testcase_08 AC 215 ms
96,444 KB
testcase_09 AC 676 ms
158,012 KB
testcase_10 AC 640 ms
163,392 KB
testcase_11 AC 667 ms
161,540 KB
testcase_12 AC 634 ms
163,356 KB
testcase_13 AC 646 ms
163,428 KB
testcase_14 AC 647 ms
163,536 KB
testcase_15 AC 671 ms
161,508 KB
testcase_16 AC 582 ms
161,296 KB
testcase_17 AC 547 ms
155,368 KB
testcase_18 AC 552 ms
163,372 KB
testcase_19 AC 568 ms
163,212 KB
testcase_20 AC 557 ms
163,208 KB
testcase_21 AC 546 ms
163,244 KB
testcase_22 AC 583 ms
163,208 KB
testcase_23 AC 528 ms
160,180 KB
testcase_24 AC 514 ms
160,028 KB
testcase_25 AC 531 ms
157,348 KB
testcase_26 AC 527 ms
159,508 KB
testcase_27 AC 537 ms
160,120 KB
testcase_28 AC 534 ms
159,536 KB
testcase_29 AC 547 ms
160,532 KB
testcase_30 AC 494 ms
161,392 KB
testcase_31 AC 571 ms
163,584 KB
testcase_32 AC 266 ms
104,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

class DualSegTree:
    def __init__(self, op, e, v):
        self._op = op
        self._e = e()
        if isinstance(v, int): v = [self._e]*v
        self._n = len(v)
        self._log = (self._n-1).bit_length()
        self._size = 1 << self._log
        self._d = [self._e]*(2*self._size)

        for i in range(self._n):
            self._d[self._size+i] = v[i]

    def apply(self, left, right, f):
        assert 0 <= left <= right <= self._n
        if left == right: return
        left += self._size
        right += self._size

        for i in range(self._log, 0, -1):
            if ((left >> i) << i) != left:
                self._push(left >> i)
            if ((right >> i) << i) != right:
                self._push((right-1) >> i)

        while left < right:
            if left & 1:
                self._d[left] = self._op(self._d[left], f)
                left += 1
            if right & 1:
                right -= 1
                self._d[right] = self._op(self._d[right], f)
            left >>= 1
            right >>= 1

    def get(self, p):
        assert 0 <= p < self._n
        p += self._size
        res = self._e
        while p:
            res = self._op(res, self._d[p])
            p >>= 1
        return res

    def all_array(self):
        res = []
        for i in range(self._n):
            res.append(self.get(i))
        return res

    def _push(self, k):
        self._d[k*2] = self._op(self._d[k*2], self._d[k])
        self._d[k*2+1] = self._op(self._d[k*2+1], self._d[k])
        self._d[k] = self._e

# ノードfの値をgで更新
def op(f, g):
    return min(f, g)

# 単位元
def e():
    return 10**16

n,a=LI()
xx=LI()
t=II()
lr=[]
dec=set(xx)
for _ in range(t):
    l,r=LI()
    r+=1
    lr.append((l,r))
    dec.add(l)
    dec.add(r)

enc={a:i for i,a in enumerate(sorted(dec))}
a=len(enc)
st=DualSegTree(max,lambda :-1,a+5)
for i,(l,r) in enumerate(lr,1):
    l=enc[l]
    r=enc[r]
    st.apply(l,r,i)
for x in xx:
    x=enc[x]
    print(st.get(x))
0