結果

問題 No.1441 MErGe
ユーザー c-yanc-yan
提出日時 2021-03-28 22:33:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,753 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 119,324 KB
最終ジャッジ日時 2023-08-19 15:51:31
合計ジャッジ時間 11,054 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
75,800 KB
testcase_01 AC 75 ms
71,484 KB
testcase_02 AC 73 ms
71,272 KB
testcase_03 AC 116 ms
77,628 KB
testcase_04 AC 119 ms
77,944 KB
testcase_05 AC 171 ms
78,284 KB
testcase_06 AC 171 ms
78,856 KB
testcase_07 AC 175 ms
79,036 KB
testcase_08 AC 439 ms
86,916 KB
testcase_09 AC 436 ms
85,940 KB
testcase_10 AC 661 ms
90,660 KB
testcase_11 AC 571 ms
89,376 KB
testcase_12 AC 624 ms
90,264 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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(x, y + 1):
            st[j] = st[x]
        st.range_add(y + 1, N + 1, l - r)
    elif T == 2:
        if x != 0:
            result.append(A[y] - A[x - 1])
        else:
            result.append(A[y])
print(*result, sep='\n')
0