結果

問題 No.1441 MErGe
ユーザー c-yanc-yan
提出日時 2021-03-28 23:23:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,900 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 255,544 KB
最終ジャッジ日時 2023-08-19 15:56:16
合計ジャッジ時間 8,723 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 OLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
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(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