結果
問題 | No.1625 三角形の質問 |
ユーザー | mkawa2 |
提出日時 | 2021-07-25 14:16:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,527 ms / 6,000 ms |
コード長 | 3,755 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 290,636 KB |
最終ジャッジ日時 | 2024-07-20 22:23:03 |
合計ジャッジ時間 | 35,688 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,248 KB |
testcase_01 | AC | 345 ms
89,652 KB |
testcase_02 | AC | 1,311 ms
203,676 KB |
testcase_03 | AC | 538 ms
113,464 KB |
testcase_04 | AC | 782 ms
146,412 KB |
testcase_05 | AC | 1,160 ms
188,644 KB |
testcase_06 | AC | 2,318 ms
289,428 KB |
testcase_07 | AC | 2,369 ms
289,080 KB |
testcase_08 | AC | 2,527 ms
290,636 KB |
testcase_09 | AC | 2,355 ms
289,552 KB |
testcase_10 | AC | 2,362 ms
289,392 KB |
testcase_11 | AC | 2,288 ms
289,164 KB |
testcase_12 | AC | 2,325 ms
289,112 KB |
testcase_13 | AC | 2,331 ms
289,000 KB |
testcase_14 | AC | 2,352 ms
290,292 KB |
testcase_15 | AC | 2,526 ms
289,128 KB |
testcase_16 | AC | 889 ms
284,572 KB |
testcase_17 | AC | 930 ms
289,192 KB |
testcase_18 | AC | 1,858 ms
282,560 KB |
testcase_19 | AC | 934 ms
285,360 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 md = 998244353 # md = 10**9+7 # 内部で1-indexedに変えるので入力は0-indexedでよい # jは内部で座圧する # nはiの最大値+1(リストの長さ) class BitMax2D: class Node: def __init__(self): self.st = set() def comp(self): self.enc = {a: i for i, a in enumerate(sorted(self.st))} self.bit = BitMax(len(self.enc)) def update(self, j, val): j = self.enc[j] self.bit.update(j, val) def max(self, j): j = self.enc[j] return self.bit.max(j) def __init__(self, n): self.inf = 10**16 self.n = n self.table = [self.Node() for _ in range(n+1)] # インデックスの先読み def pre_read(self, i, j): i = k = i+1 while i <= self.n: self.table[i].st.add(j) i += i & -i while k > 0: self.table[k].st.add(j) k -= k & -k # 先読み終了後に準備 def prep(self): for i in range(self.n): self.table[i+1].comp() def update(self, i, j, val): i += 1 while i <= self.n: self.table[i].update(j, val) i += i & -i def max(self, i, j): i += 1 res = -self.inf while i > 0: cur = self.table[i].max(j) if cur > res: res = cur i -= i & -i return res class BitMax: def __init__(self, n): self.inf = 10**16 self.n = n self.table = [-self.inf]*(self.n+1) def update(self, i, x): i += 1 while i <= self.n: if x > self.table[i]: self.table[i] = x i += i & -i def max(self, i): i += 1 res = -self.inf while i > 0: if self.table[i] > res: res = self.table[i] i -= i & -i return res def space(a, b, c, d, e, f): a, b, c, d = a-e, b-f, c-e, d-f return abs(a*d-b*c) n, q = LI() bit2 = BitMax2D(q) st = set() pre = [] for _ in range(n): a, b, c, d, e, f = LI() l = min(a, c, e) r = max(a, c, e) s = space(a, b, c, d, e, f) pre.append((l, r, s)) st.add(r) pre.sort(key=lambda x: -x[0]) ask = [] pos = [] for i in range(q): tx = LI() if tx[0] == 1: _, a, b, c, d, e, f = tx l = min(a, c, e) r = max(a, c, e) s = space(a, b, c, d, e, f) pos.append((l, r, i, s)) else: _, l, r = tx ask.append((l, r, i, len(ask))) st.add(r) bit2.pre_read(i, r) ask.sort(key=lambda x: -x[0]) pos.sort(key=lambda x: x[0]) enc = {a: i for i, a in enumerate(sorted(st))} bit = BitMax(len(enc)) ans = [0]*len(ask) k = 0 for l, r, i, j in ask: while k < len(pre) and pre[k][0] >= l: _, R, s = pre[k] R = enc[R] bit.update(R, s) k += 1 r = enc[r] ans[j] = bit.max(r) # print(ans) bit2.prep() for l, r, i, j in ask: while pos and pos[-1][0] >= l: l0, r0, i0, s = pos.pop() bit2.update(i0, r0, s) mx = bit2.max(i, r) if mx > ans[j]: ans[j] = mx for a in ans: if a == -inf: a = -1 print(a)