結果

問題 No.1074 増殖
ユーザー tktk_snsntktk_snsn
提出日時 2022-07-24 08:46:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 2,241 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 93,168 KB
最終ジャッジ日時 2023-09-20 04:49:12
合計ジャッジ時間 4,599 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
72,580 KB
testcase_01 AC 73 ms
72,648 KB
testcase_02 AC 77 ms
72,636 KB
testcase_03 AC 73 ms
72,492 KB
testcase_04 AC 77 ms
76,808 KB
testcase_05 AC 78 ms
76,836 KB
testcase_06 AC 318 ms
91,580 KB
testcase_07 AC 282 ms
91,176 KB
testcase_08 AC 316 ms
92,700 KB
testcase_09 AC 366 ms
93,168 KB
testcase_10 AC 210 ms
89,752 KB
testcase_11 AC 222 ms
90,052 KB
testcase_12 AC 216 ms
89,992 KB
testcase_13 AC 358 ms
91,888 KB
testcase_14 AC 353 ms
92,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
U = 2 * 10 ** 4 + 10


class FenwickTree(object):
    def __init__(self, n):
        self.n = n
        self.log = n.bit_length()
        self.data = [0] * n

    def __sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def add(self, p, x):
        """ a[p] += xを行う"""
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        """a[l] + a[l+1] + .. + a[r-1]を返す"""
        return self.__sum(r) - self.__sum(l)

    def lower_bound(self, x):
        """a[0] + a[1] + .. a[i] >= x となる最小のiを返す"""
        if x <= 0:
            return -1
        i = 0
        k = 1 << self.log
        while k:
            if i + k <= self.n and self.data[i + k - 1] < x:
                x -= self.data[i + k - 1]
                i += k
            k >>= 1
        return i

    def __repr__(self):
        res = [self.sum(i, i+1) for i in range(self.n)]
        return " ".join(map(str, res))


def solve(N, X, Y):
    height = [0] * (U + 1)
    height[0] = U
    bit = FenwickTree(U + 1)
    bit.add(0, 1)
    bit.add(U, 1)

    res = []

    for x, y in zip(X, Y):
        c = bit.sum(0, x)
        yr = height[bit.lower_bound(c + 1)]
        if yr >= y:
            res.append(0)
            continue

        point = bit.sum(0, x+1)
        area = 0
        while point > 1:
            xl = bit.lower_bound(point)
            yl = height[xl]
            if yl > y:
                break

            xll = bit.lower_bound(point-1)
            area -= (xl - xll) * (yl - yr)
            point -= 1

            bit.add(xl, -1)
            height[xl] = 0

        xl = bit.lower_bound(point)
        area += (x - xl) * (y - yr)

        res.append(area)
        height[x] = y
        bit.add(x, 1)
    return res


N = int(input())
data = tuple(tuple(map(lambda x: abs(int(x)), input().split()))
             for _ in range(N))
x, y, xx, yy = zip(*data)

a1 = solve(N, x, y)
a2 = solve(N, x, yy)
a3 = solve(N, xx, y)
a4 = solve(N, xx, yy)
for i in range(N):
    print(a1[i] + a2[i] + a3[i] + a4[i])
0