結果

問題 No.1074 増殖
ユーザー neterukunneterukun
提出日時 2020-06-05 22:39:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,156 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 102,860 KB
最終ジャッジ日時 2024-05-09 22:19:20
合計ジャッジ時間 16,717 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
56,832 KB
testcase_01 AC 49 ms
64,120 KB
testcase_02 AC 42 ms
56,960 KB
testcase_03 AC 41 ms
56,576 KB
testcase_04 AC 59 ms
69,248 KB
testcase_05 AC 58 ms
67,712 KB
testcase_06 AC 1,679 ms
90,312 KB
testcase_07 AC 719 ms
89,588 KB
testcase_08 AC 1,700 ms
91,312 KB
testcase_09 AC 859 ms
98,064 KB
testcase_10 AC 769 ms
88,476 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
権限があれば一括ダウンロードができます

ソースコード

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


m = int(input())
info = [list(map(int, input().split())) for i in range(m)]
INF = 0

ans = [0] * m
N = 20000 + 10
LV = (N-1).bit_length()
N0 = 2**LV

# 右上
data = [INF]*(2*N0)
lazy = [None]*(2*N0)
for i in range(m):
    _, _, x, y = info[i]
    ok = 20000 + 10
    ng = 0
    if query(0, 1) <= y:
        ok = 0
    else:
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if query(mid, mid + 1) <= y:
                ok = mid
            else:
                ng = mid
    if ok < x:
        update(ok, x, y)
    ans[i] += query(0, N)

# 右下
data = [INF]*(2*N0)
lazy = [None]*(2*N0)
for i in range(m):
    _, y, x, _ = info[i]
    y *= -1
    ok = 20000 + 10
    ng = 0
    if query(0, 1) <= y:
        ok = 0
    else:
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if query(mid, mid + 1) <= y:
                ok = mid
            else:
                ng = mid
    if ok < x:
        update(ok, x, y)
    ans[i] += query(0, N)

# 左上
data = [INF]*(2*N0)
lazy = [None]*(2*N0)
for i in range(m):
    x, _, _, y = info[i]
    x *= -1
    ok = 20000 + 10
    ng = 0
    if query(0, 1) <= y:
        ok = 0
    else:
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if query(mid, mid + 1) <= y:
                ok = mid
            else:
                ng = mid
    if ok < x:
        update(ok, x, y)
    ans[i] += query(0, N)

# 左下
data = [INF]*(2*N0)
lazy = [None]*(2*N0)
for i in range(m):
    x, y, _, _ = info[i]
    x *= -1
    y *= -1
    ok = 20000 + 10
    ng = 0
    if query(0, 1) <= y:
        ok = 0
    else:
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if query(mid, mid + 1) <= y:
                ok = mid
            else:
                ng = mid
    if ok < x:
        update(ok, x, y)
    ans[i] += query(0, N)

print(ans[0])
for i in range(m - 1):
    print(ans[i + 1] - ans[i])
0