結果

問題 No.1441 MErGe
ユーザー mkawa2mkawa2
提出日時 2022-01-23 18:32:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 611 ms / 1,000 ms
コード長 1,306 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 116,668 KB
最終ジャッジ日時 2023-08-20 00:08:12
合計ジャッジ時間 14,881 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,556 KB
testcase_01 AC 81 ms
71,228 KB
testcase_02 AC 76 ms
71,240 KB
testcase_03 AC 111 ms
77,636 KB
testcase_04 AC 106 ms
77,888 KB
testcase_05 AC 153 ms
78,536 KB
testcase_06 AC 161 ms
78,480 KB
testcase_07 AC 151 ms
78,528 KB
testcase_08 AC 232 ms
85,720 KB
testcase_09 AC 245 ms
84,556 KB
testcase_10 AC 324 ms
84,024 KB
testcase_11 AC 287 ms
82,808 KB
testcase_12 AC 300 ms
85,868 KB
testcase_13 AC 498 ms
115,836 KB
testcase_14 AC 593 ms
115,984 KB
testcase_15 AC 611 ms
112,548 KB
testcase_16 AC 483 ms
114,504 KB
testcase_17 AC 479 ms
112,212 KB
testcase_18 AC 421 ms
97,188 KB
testcase_19 AC 463 ms
109,968 KB
testcase_20 AC 381 ms
108,048 KB
testcase_21 AC 355 ms
101,220 KB
testcase_22 AC 465 ms
100,604 KB
testcase_23 AC 586 ms
116,444 KB
testcase_24 AC 585 ms
116,540 KB
testcase_25 AC 554 ms
116,668 KB
testcase_26 AC 583 ms
116,424 KB
testcase_27 AC 542 ms
116,572 KB
testcase_28 AC 299 ms
116,116 KB
testcase_29 AC 312 ms
116,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def LI(): return list(map(int, sys.stdin.readline().split()))

class BitSum:
    def __init__(self, n):
        self.n = n+1
        self.table = [0]*self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

    def rank(self, x):
        idx = 0
        for lv in range((self.n-1).bit_length()-1, -1, -1):
            mid = idx+(1 << lv)
            if mid >= self.n: continue
            if self.table[mid] < x:
                x -= self.table[mid]
                idx += 1 << lv
        return idx

def main():
    n, q = LI()
    aa = LI()

    cs = [0]
    for a in aa: cs.append(cs[-1]+a)

    bit = BitSum(n)
    for i in range(1, n): bit.add(i, 1)

    lr = list(range(n))

    for _ in range(q):
        t, l, r = LI()
        l -= 1
        if t == 1:
            i = bit.rank(l)
            for _ in range(r-l-1):
                j = lr[i]+1
                bit.add(j, -1)
                k = lr[j]
                lr[k] = i
                lr[i] = k
        else:
            i = bit.rank(l)
            j = bit.rank(r)
            print(cs[j]-cs[i])

main()
0