結果

問題 No.1441 MErGe
ユーザー c-yanc-yan
提出日時 2021-03-28 22:39:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,774 bytes
コンパイル時間 1,351 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 123,292 KB
最終ジャッジ日時 2023-08-19 15:52:38
合計ジャッジ時間 11,958 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,280 KB
testcase_01 AC 73 ms
71,480 KB
testcase_02 AC 72 ms
71,156 KB
testcase_03 AC 110 ms
77,648 KB
testcase_04 AC 113 ms
77,716 KB
testcase_05 AC 154 ms
78,252 KB
testcase_06 AC 160 ms
78,964 KB
testcase_07 AC 156 ms
78,464 KB
testcase_08 AC 391 ms
86,864 KB
testcase_09 AC 393 ms
85,796 KB
testcase_10 AC 581 ms
90,624 KB
testcase_11 AC 532 ms
89,920 KB
testcase_12 AC 540 ms
90,232 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 973 ms
100,776 KB
testcase_21 AC 870 ms
101,736 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
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(bisect_left(st, l + 1), 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