結果

問題 No.318 学学学学学
ユーザー 👑 timitimi
提出日時 2020-12-15 13:35:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 724 ms / 2,000 ms
コード長 1,583 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 112,336 KB
最終ジャッジ日時 2023-10-20 05:59:05
合計ジャッジ時間 11,864 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
78,812 KB
testcase_01 AC 186 ms
81,800 KB
testcase_02 AC 210 ms
83,372 KB
testcase_03 AC 166 ms
80,188 KB
testcase_04 AC 193 ms
81,932 KB
testcase_05 AC 720 ms
112,336 KB
testcase_06 AC 614 ms
106,296 KB
testcase_07 AC 497 ms
100,692 KB
testcase_08 AC 407 ms
96,936 KB
testcase_09 AC 340 ms
93,840 KB
testcase_10 AC 256 ms
94,756 KB
testcase_11 AC 724 ms
111,540 KB
testcase_12 AC 519 ms
102,700 KB
testcase_13 AC 466 ms
98,336 KB
testcase_14 AC 369 ms
95,536 KB
testcase_15 AC 325 ms
93,360 KB
testcase_16 AC 258 ms
94,796 KB
testcase_17 AC 400 ms
102,100 KB
testcase_18 AC 389 ms
102,064 KB
testcase_19 AC 399 ms
102,100 KB
testcase_20 AC 269 ms
93,332 KB
testcase_21 AC 36 ms
53,488 KB
testcase_22 AC 36 ms
53,488 KB
testcase_23 AC 36 ms
53,488 KB
testcase_24 AC 37 ms
53,488 KB
testcase_25 AC 36 ms
53,488 KB
testcase_26 AC 37 ms
53,488 KB
testcase_27 AC 37 ms
53,488 KB
testcase_28 AC 36 ms
53,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 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(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = lazy[2*i] = data[2*i-1] = data[2*i] = v >> 1
        lazy[i-1] = None

# 区間[l, r)をxに更新
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    v = x
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = v
        if L & 1:
            lazy[L-1] = data[L-1] = v
            L += 1
        L >>= 1; R >>= 1; v <<= 1
    for i in ids:
        data[i-1] = data[2*i-1] + data[2*i]

# 区間[l, r)内の合計を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = 0
    while L < R:
        if R & 1:
            R -= 1
            s += data[R-1]
        if L & 1:
            s += data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s
N=int(input())
n=N
A=list(map(int, input().split()))
D={}
for i in range(N):
  if A[i] not in D:
    D[A[i]]=[i,i]
  else:
    D[A[i]][-1]=i

D=sorted(D.items())
# N: 処理する区間の長さ
LV=(N-1).bit_length()
N0=2**LV
data=[0]*(2*N0)
lazy=[None]*(2*N0)
for a,b in D:
  update(b[0],b[1]+1,a)
F=[]
for i in range(N):
  F.append(query(i,i+1))
print(*F)
0