結果

問題 No.1558 Derby Live
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-06-26 17:23:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,530 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 117,376 KB
最終ジャッジ日時 2023-09-07 15:21:43
合計ジャッジ時間 16,965 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 505 ms
117,376 KB
testcase_02 AC 68 ms
71,412 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 314 ms
89,928 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 68 ms
71,292 KB
testcase_34 AC 70 ms
71,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    """ define what you want to do with 0 index, ex) size = tree_size, func = min or max, sta = default_value """
    
    def __init__(self,size,func,sta):
        self.n = size
        self.size = 1 << size.bit_length()
        self.func = func
        self.sta = sta
        self.tree = [sta]*(2*self.size)

    def set(self,i,x):
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    
    def get(self,l,r):
        """ take the value of [l r) with func (min or max)"""
        l += self.size
        r += self.size
        res = self.sta

        while l < r:
            if l & 1:
                res = self.func(self.tree[l],res)
                l += 1
            if r & 1:
                res = self.func(self.tree[r-1],res)
            l >>= 1
            r >>= 1
        return res
        

n,m,q = map(int,input().split())
Q = [list(map(int,input().split())) for i in range(q)]

def func(a,b):
    return [b[aa] for aa in a]
seg = SegTree(m,func,[i for i in range(n)])

def sol(A):
    ans = [0]*n
    for i,a in enumerate(A):
        ans[a] = i+1
    return ans
for q in Q:
    id = q[0]
    if id == 1:
        d = q[1]
        p = [x-1 for x in q[2:]]
        seg.set(d-1,p)

    elif id == 2:
        print(*sol(seg.get(0,q[1])))
    
    else:
        l,r = q[1:]
        a = seg.get(l-1,r)
        ans = 0
        for i in range(n):
            ans += abs(i-a[i])
        print(ans)
0