結果

問題 No.318 学学学学学
ユーザー tjaketjake
提出日時 2015-12-13 11:40:54
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,621 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 38,552 KB
最終ジャッジ日時 2023-11-22 00:28:44
合計ジャッジ時間 15,963 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
9,476 KB
testcase_01 AC 259 ms
11,548 KB
testcase_02 AC 306 ms
12,168 KB
testcase_03 AC 195 ms
10,528 KB
testcase_04 AC 265 ms
11,704 KB
testcase_05 AC 1,621 ms
38,552 KB
testcase_06 AC 958 ms
29,864 KB
testcase_07 AC 714 ms
28,712 KB
testcase_08 AC 506 ms
23,780 KB
testcase_09 AC 350 ms
23,140 KB
testcase_10 AC 214 ms
21,220 KB
testcase_11 AC 1,617 ms
38,552 KB
testcase_12 AC 907 ms
29,864 KB
testcase_13 AC 670 ms
28,584 KB
testcase_14 AC 479 ms
23,780 KB
testcase_15 AC 338 ms
23,140 KB
testcase_16 AC 212 ms
21,220 KB
testcase_17 AC 845 ms
29,468 KB
testcase_18 AC 850 ms
29,480 KB
testcase_19 AC 846 ms
29,468 KB
testcase_20 AC 214 ms
19,876 KB
testcase_21 AC 11 ms
6,676 KB
testcase_22 AC 11 ms
6,676 KB
testcase_23 AC 11 ms
6,676 KB
testcase_24 AC 11 ms
6,676 KB
testcase_25 AC 10 ms
6,676 KB
testcase_26 AC 11 ms
6,676 KB
testcase_27 AC 11 ms
6,676 KB
testcase_28 AC 11 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class StarrySkyTree:
    def __init__(self, n_):
        self.n = n = 2**n_.bit_length()
        self.data = [0]*(2*n)
    
    def update(self, k, a):
        data = self.data
        k += self.n-1
        data[k] = a
        while k>0:
            k = (k - 1) / 2
            data[k] = max(data[2*k+1], data[2*k+2])
    
    def query(self, a, b, k, l, r):
        if b<=l or r<=a:
            return 0
        if l<=a and b<=r:
            return self.data[k]

        vl = self.query(a, b, 2*k+1, l, (l + r) / 2)
        vr = self.query(a, b, 2*k+2, (l + r) / 2, r)

        return max(vl, vr)

    def get_max(self, a, b):
        return self.query(a, b, 0, 0, self.n)

n = input()
a = map(int, raw_input().split())
s = set(a)
mapping = {e: i for i, e in enumerate(s)}
b = [mapping[e] for e in a]

le = [None]*n
ri = [None]*n

for i in xrange(n):
    if le[b[i]] is None:
        le[b[i]] = i
for i in xrange(n-1,-1,-1):
    if ri[b[i]] is None:
        ri[b[i]] = i

sst = StarrySkyTree(n)
ans = []
append = ans.append
for i in xrange(n):
    e = a[i]
    p = b[i]
    if le[p]==i:
        sst.update(p, e)
    append(sst.get_max(0, n))
    if ri[p]==i:
        sst.update(p, 0)
print " ".join(map(str, ans))
0