提出 #71860102


ソースコード 拡げる




import sys

input = sys.stdin.readline
INF = 10**18

class SegTree:
    def __init__(self, size_exp:int, op, ele):
        self.size = 1 << size_exp  
        self.op = op
        self.ele = ele
        self.tree = [self.ele] * (2 * self.size)

    def update(self, p: int, x: int):
        p += self.size
        self.tree[p] = x
        
        # 親に向かって更新
        while p > 1:
            p //= 2
            self.tree[p] = self.op(self.tree[2*p], self.tree[2*p+1])

    def get(self, l: int, r: int):
        l += self.size
        r += self.size
        
        # 左右から結果を集めるリストではなく、直接演算していく
        res_l = self.ele
        res_r = self.ele
        
        while l < r:
            if l % 2 == 1:
                res_l = self.op(res_l, self.tree[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res_r = self.op(self.tree[r], res_r)
            l //= 2
            r //= 2
            
        return self.op(res_l, res_r)


N,Q = map(int,input().split())
XY = [list(map(int, input().split())) for _ in range(N)]


size_exp = (N-1).bit_length()
#T1: x + y, T2: x - y, T3: -x + y, T4: -x - y
T1 = SegTree(size_exp, max, -INF)
T2 = SegTree(size_exp, max, -INF)
T3 = SegTree(size_exp, max, -INF)
T4 = SegTree(size_exp, max, -INF)


for i in range(N):
    x, y = XY[i]
    T1.update(i, x + y)
    T2.update(i, x - y)
    T3.update(i, -x + y)
    T4.update(i, -x - y)



for _ in range(Q):
    query = list(map(str, input().split()))
    
    if query[0] == '1':
        # 1 i x y : 更新
        i = int(query[1]) - 1 # 0-indexed
        x = int(query[2])
        y = int(query[3])
        
        T1.update(i, x + y)
        T2.update(i, x - y)
        T3.update(i, -x + y)
        T4.update(i, -x - y)
        
    else:
        # 2 L R x y : クエリ
        L = int(query[1]) - 1 # 0-indexed
        R = int(query[2])     
        x = int(query[3])
        y = int(query[4])
        
        #最大値を取得
        v1 = T1.get(L, R)
        v2 = T2.get(L, R)
        v3 = T3.get(L, R)
        v4 = T4.get(L, R)
        
        # 式に合わせて計算し、最大を取る
        # max( (Xi+Yi)-(x+y), (Xi-Yi)-(x-y), (-Xi+Yi)-(-x+y), (-Xi-Yi)-(-x-y) )
        ans = -INF
        ans = max(ans, v1 - (x + y))
        ans = max(ans, v2 - (x - y))
        ans = max(ans, v3 - (-x + y))
        ans = max(ans, v4 - (-x - y))
        
        print(ans)

提出情報

提出日時
問題 F - Manhattan Christmas Tree 2
ユーザ exophia
言語 Python (PyPy 3.11-v7.3.20)
得点 500
コード長 2584 Byte
結果 AC
実行時間 1043 ms
メモリ 150460 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 24
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 59 ms 80120 KiB
00_sample_01.txt AC 59 ms 80580 KiB
01_random_00.txt AC 897 ms 149936 KiB
01_random_01.txt AC 946 ms 150028 KiB
01_random_02.txt AC 999 ms 149856 KiB
01_random_03.txt AC 1001 ms 150180 KiB
01_random_04.txt AC 1015 ms 150440 KiB
01_random_05.txt AC 1041 ms 150296 KiB
01_random_06.txt AC 1043 ms 150460 KiB
01_random_07.txt AC 1032 ms 150232 KiB
01_random_08.txt AC 1037 ms 150384 KiB
01_random_09.txt AC 1026 ms 150148 KiB
01_random_10.txt AC 811 ms 149636 KiB
01_random_11.txt AC 820 ms 149788 KiB
01_random_12.txt AC 796 ms 149832 KiB
01_random_13.txt AC 801 ms 149628 KiB
01_random_14.txt AC 814 ms 149780 KiB
01_random_15.txt AC 371 ms 110068 KiB
01_random_16.txt AC 513 ms 147892 KiB
01_random_17.txt AC 753 ms 149436 KiB
01_random_18.txt AC 742 ms 149624 KiB
01_random_19.txt AC 737 ms 149684 KiB
01_random_20.txt AC 730 ms 149556 KiB
01_random_21.txt AC 729 ms 149392 KiB