結果

問題 No.1074 増殖
ユーザー tktk_snsn
提出日時 2022-07-24 08:32:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,169 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 90,880 KB
最終ジャッジ日時 2024-07-06 00:08:00
合計ジャッジ時間 4,945 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 WA * 2 TLE * 1 -- * 7
権限があれば一括ダウンロードができます

ソースコード

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 = 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
xl = bit.lower_bound(point)
area += (x - xl) * (y - yr)
res.append(area)
height[x] = y
bit.add(x, y)
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])
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0