結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー lilictakalilictaka
提出日時 2022-10-17 16:33:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,629 ms / 6,000 ms
コード長 2,240 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 252,496 KB
最終ジャッジ日時 2023-09-10 15:48:08
合計ジャッジ時間 81,746 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,488 KB
testcase_01 AC 95 ms
71,608 KB
testcase_02 AC 94 ms
71,388 KB
testcase_03 AC 1,310 ms
163,504 KB
testcase_04 AC 1,893 ms
206,512 KB
testcase_05 AC 1,223 ms
151,012 KB
testcase_06 AC 1,712 ms
196,496 KB
testcase_07 AC 1,951 ms
207,056 KB
testcase_08 AC 1,858 ms
213,596 KB
testcase_09 AC 1,107 ms
142,300 KB
testcase_10 AC 1,031 ms
135,604 KB
testcase_11 AC 1,465 ms
163,988 KB
testcase_12 AC 1,462 ms
164,564 KB
testcase_13 AC 1,093 ms
141,824 KB
testcase_14 AC 962 ms
135,080 KB
testcase_15 AC 2,178 ms
222,356 KB
testcase_16 AC 1,794 ms
201,576 KB
testcase_17 AC 780 ms
120,016 KB
testcase_18 AC 2,613 ms
251,988 KB
testcase_19 AC 2,598 ms
251,552 KB
testcase_20 AC 2,627 ms
252,000 KB
testcase_21 AC 2,566 ms
251,660 KB
testcase_22 AC 2,571 ms
252,232 KB
testcase_23 AC 2,549 ms
252,056 KB
testcase_24 AC 2,629 ms
251,804 KB
testcase_25 AC 2,588 ms
252,496 KB
testcase_26 AC 2,625 ms
251,756 KB
testcase_27 AC 2,598 ms
251,892 KB
testcase_28 AC 2,518 ms
251,824 KB
testcase_29 AC 2,514 ms
251,668 KB
testcase_30 AC 2,588 ms
251,752 KB
testcase_31 AC 2,553 ms
251,852 KB
testcase_32 AC 2,576 ms
252,016 KB
testcase_33 AC 2,184 ms
250,472 KB
testcase_34 AC 2,195 ms
250,764 KB
testcase_35 AC 2,227 ms
250,708 KB
testcase_36 AC 2,237 ms
250,628 KB
testcase_37 AC 2,301 ms
250,700 KB
testcase_38 AC 464 ms
142,180 KB
testcase_39 AC 824 ms
144,800 KB
testcase_40 AC 1,065 ms
154,468 KB
testcase_41 AC 98 ms
71,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v,ope):
        self.update(i, ope(self[i],v))

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)
from collections import defaultdict
N = int(input())
A = []
T = []
for _ in range(N):
    a,t = map(int,input().split())
    A.append(a)
    T.append(t)
Q = int(input())
memo = defaultdict(list)
board = []
for i in range(N):
    memo[T[i]].append((-1,i))
    memo[T[i] + A[i]].append((0,i))
for q in range(Q):
    d,l,r = map(int,input().split())
    l-=1
    r-=1
    memo[d].append((1,q))
    board.append((l,r))
ANS = [0] * Q
keys = list(memo.keys())
keys.sort()
segcnt = SegmentTree([0] * N,lambda x,y:x+y,0)
segsum = SegmentTree([0] * N ,lambda x,y:x+y,0)
Aseg = SegmentTree(A,lambda x,y:x+y,0)
for key in keys:
    memo[key].sort()
    for t,index in memo[key]:
        if t == -1:
            segcnt.update(index,1)
            segsum.update(index,-(key-1))
        elif t == 0:
            segcnt.update(index,0)
            segsum.update(index,0)
            Aseg.update(index,0)
        else:
            l,r = board[index]
            ans = Aseg.sum(l,r+1) - (segcnt.sum(l,r+1) * key + segsum.sum(l,r+1))
            ANS[index] = ans
print(*ANS,sep='\n')
0