結果

問題 No.1000 Point Add and Array Add
ユーザー hedwig100hedwig100
提出日時 2020-04-15 14:31:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,443 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 43,664 KB
最終ジャッジ日時 2024-04-09 18:39:32
合計ジャッジ時間 16,027 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
18,080 KB
testcase_01 AC 33 ms
11,136 KB
testcase_02 AC 30 ms
11,008 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 32 ms
11,136 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 32 ms
11,008 KB
testcase_09 AC 31 ms
11,136 KB
testcase_10 AC 32 ms
11,008 KB
testcase_11 AC 31 ms
11,008 KB
testcase_12 AC 46 ms
11,136 KB
testcase_13 AC 38 ms
11,008 KB
testcase_14 AC 52 ms
11,136 KB
testcase_15 AC 43 ms
11,264 KB
testcase_16 AC 1,750 ms
38,624 KB
testcase_17 AC 1,753 ms
27,472 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 1,698 ms
33,140 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 7
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from bisect import bisect_left

class SegmentTree():

    def __init__(self,init_val,func,unit): #init_valは長さnの配列 O(2*n)
        self.unit = unit #unitは単位元
        self.size = pow(2,len(init_val) - 1).bit_length() #n以上の最小の2のべき乗
        self.seg = [self.unit] * (2 * self.size) #セグメントツリー本体
        self.f = func #セグ木により異なる関数
        
        for i in range(len(init_val)):
            self.seg[i + self.size - 1] = init_val[i] 
        
        for i in range(self.size - 2,-1,-1):
            self.seg[i] = self.f(self.seg[2 * i + 1],self.seg[2 * i + 2])
    
    def update(self,k,x): #k番目の要素をxに変更する O(logN)
        k += self.size - 1
        self.seg[k] = x
        while k:
            k = (k - 1)//2
            self.seg[k] = self.f(self.seg[2 * k + 1],self.seg[2 * k + 2])
    
    def query(self,p,q): #[p,q)のクエリに答える 半開区間であることに注意 O(logN)
        if q <= p:
            return self.unit

        p += self.size - 1 
        q += self.size - 2
        res = self.unit

        while q - p > 1:

            if (p&1) == 0:
                res = self.f(res,self.seg[p])

            if (q&1) == 1:
                res = self.f(res,self.seg[q])
                q -= 1

            p //= 2
            q = (q - 1)//2
        
        if p == q:
            res = self.f(res,self.seg[p])
        else:
            res = self.f(self.f(res,self.seg[p]),self.seg[q])
        
        return res

def f(x,y):
    return x + y

def main():
    n,q = map(int,input().split())
    a = list(map(int,input().split()))
    b = [0] * n
    cnt = [0] * n
    st = SegmentTree([0] * n,f,0)

    for _ in range(q):
        t,x,y = map(str,input().split())
        x = int(x)
        y = int(y)
        if t == 'A':
            x -= 1
            c = st.query(0,x + 1)
            b[x] -= c * y
            a[x] += y
        else:
            x -= 1
            y -= 1
            cnt[x] += 1
            st.update(x,cnt[x])
            if y < n - 1:
                cnt[y + 1] -= 1
                st.update(y + 1,cnt[y + 1])
    
    b[0] += cnt[0] * a[0]
    for i in range(1,n):
        cnt[i] += cnt[i - 1]
        b[i] += cnt[i] * a[i]

    print(*b)

if __name__ == '__main__':
    main()
0