結果

問題 No.1441 MErGe
ユーザー c-yanc-yan
提出日時 2021-03-28 23:24:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,902 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 122,772 KB
最終ジャッジ日時 2023-08-19 15:56:57
合計ジャッジ時間 9,556 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,260 KB
testcase_01 AC 65 ms
71,392 KB
testcase_02 AC 62 ms
71,276 KB
testcase_03 AC 100 ms
77,792 KB
testcase_04 AC 110 ms
78,028 KB
testcase_05 AC 163 ms
79,008 KB
testcase_06 AC 184 ms
80,012 KB
testcase_07 AC 158 ms
79,188 KB
testcase_08 AC 452 ms
87,200 KB
testcase_09 AC 441 ms
87,916 KB
testcase_10 AC 573 ms
89,972 KB
testcase_11 AC 556 ms
90,624 KB
testcase_12 AC 615 ms
91,160 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit, stdin
from itertools import accumulate
from bisect import bisect_left


class RangeAddSegmentTree:
    def __init__(self, size):
        self._size = size
        t = 1
        while t < size:
            t *= 2
        self._offset = t - 1
        self._data = [0] * (t * 2 - 1)

    def __len__(self):
        return self._size

    def range_add(self, start, stop, x):
        data = self._data
        l = start + self._offset
        r = stop + self._offset
        while l < r:
            if l & 1 == 0:
                data[l] += x
            if r & 1 == 0:
                data[r - 1] += x
            l = l // 2
            r = (r - 1) // 2

    def __setitem__(self, key, val):
        self.range_add(key, key + 1, val - self[key])

    def __getitem__(self, key):
        data = self._data
        i = key + self._offset
        result = data[i]
        while i > 0:
            i = (i - 1) // 2
            result += data[i]
        return result

    def __iter__(self):
        for i in range(self._size):
            yield self[i]


readline = stdin.readline
setrecursionlimit(10 ** 6)

N, Q = map(int, readline().split())
A = list(map(int, readline().split()))

A = list(accumulate(A))
st = RangeAddSegmentTree(N + 1)
for i in range(N + 1):
    st.range_add(i, i + 1, i)

result = []
for _ in range(Q):
    T, l, r = map(int, readline().split())
    l, r = l - 1, r - 1

    x = bisect_left(st, l)
    y = bisect_left(st, r + 1) - 1
    if T == 1:
        for j in range(l + 1, r+1):
            #print("add", bisect_left(st, j), bisect_left(st, j + 1), l - j)
            st.range_add(bisect_left(st, j), bisect_left(st, j + 1), l - j)
        st.range_add(y + 1, N + 1, l - r)
        #print(*st)
    elif T == 2:
        if x != 0:
            result.append(A[y] - A[x - 1])
        else:
            result.append(A[y])
print(*result, sep='\n')
0