結果

問題 No.1625 三角形の質問
ユーザー mkawa2mkawa2
提出日時 2021-07-25 14:16:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,835 ms / 6,000 ms
コード長 3,755 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 290,480 KB
最終ジャッジ日時 2023-09-28 03:48:19
合計ジャッジ時間 38,482 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,308 KB
testcase_01 AC 355 ms
91,232 KB
testcase_02 AC 1,357 ms
205,332 KB
testcase_03 AC 625 ms
116,740 KB
testcase_04 AC 867 ms
148,644 KB
testcase_05 AC 1,225 ms
188,220 KB
testcase_06 AC 2,493 ms
290,480 KB
testcase_07 AC 2,489 ms
289,276 KB
testcase_08 AC 2,447 ms
290,084 KB
testcase_09 AC 2,453 ms
289,236 KB
testcase_10 AC 2,457 ms
289,488 KB
testcase_11 AC 2,465 ms
289,940 KB
testcase_12 AC 2,548 ms
290,152 KB
testcase_13 AC 2,835 ms
289,752 KB
testcase_14 AC 2,539 ms
288,664 KB
testcase_15 AC 2,535 ms
289,660 KB
testcase_16 AC 941 ms
285,412 KB
testcase_17 AC 933 ms
290,176 KB
testcase_18 AC 1,925 ms
283,936 KB
testcase_19 AC 974 ms
285,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0