結果

問題 No.1074 増殖
ユーザー tktk_snsntktk_snsn
提出日時 2022-07-24 08:40:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,229 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 93,700 KB
最終ジャッジ日時 2023-09-20 04:00:20
合計ジャッジ時間 5,159 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
72,540 KB
testcase_01 AC 81 ms
72,256 KB
testcase_02 AC 81 ms
72,704 KB
testcase_03 AC 82 ms
72,444 KB
testcase_04 AC 85 ms
77,128 KB
testcase_05 AC 85 ms
77,188 KB
testcase_06 WA -
testcase_07 AC 296 ms
91,016 KB
testcase_08 AC 331 ms
92,632 KB
testcase_09 AC 376 ms
91,696 KB
testcase_10 AC 391 ms
93,204 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

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+1)
        yr = height[bit.lower_bound(c + 1)]
        if yr >= y:
            res.append(0)
            continue

        point = c
        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