結果
問題 | No.1074 増殖 |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
import sysinput = sys.stdin.buffer.readlinesys.setrecursionlimit(10 ** 7)U = 2 * 10 ** 4 + 10class FenwickTree(object):def __init__(self, n):self.n = nself.log = n.bit_length()self.data = [0] * ndef __sum(self, r):s = 0while r > 0:s += self.data[r - 1]r -= r & -rreturn sdef add(self, p, x):""" a[p] += xを行う"""p += 1while p <= self.n:self.data[p - 1] += xp += p & -pdef 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 -1i = 0k = 1 << self.logwhile k:if i + k <= self.n and self.data[i + k - 1] < x:x -= self.data[i + k - 1]i += kk >>= 1return idef __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] = Ubit = 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)continuepoint = carea = 0while point > 1:xl = bit.lower_bound(point)yl = height[xl]if yl > y:breakxll = bit.lower_bound(point-1)area -= (xl - xll) * (yl - yr)point -= 1xl = bit.lower_bound(point)area += (x - xl) * (y - yr)res.append(area)height[x] = ybit.add(x, y)return resN = 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])