結果

問題 No.631 Noelちゃんと電車旅行
ユーザー furafura
提出日時 2020-10-16 17:26:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 203,256 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-10 08:04:10
合計ジャッジ時間 5,899 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
6,816 KB
testcase_01 AC 128 ms
8,192 KB
testcase_02 AC 129 ms
8,192 KB
testcase_03 AC 129 ms
8,320 KB
testcase_04 AC 128 ms
8,320 KB
testcase_05 AC 133 ms
8,192 KB
testcase_06 AC 50 ms
6,940 KB
testcase_07 AC 33 ms
6,944 KB
testcase_08 AC 94 ms
8,064 KB
testcase_09 AC 106 ms
6,940 KB
testcase_10 AC 80 ms
8,192 KB
testcase_11 AC 71 ms
6,944 KB
testcase_12 AC 90 ms
8,192 KB
testcase_13 AC 76 ms
6,944 KB
testcase_14 AC 32 ms
6,940 KB
testcase_15 AC 66 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class starry_sky_tree{
	int n;
	vector<lint> dat1,dat2;

	void add(int l,int r,int a,int b,int u,lint val){
		if(b<=l || r<=a) return;
		if(l<=a && b<=r){ dat1[u]+=val; return; }

		add(l,r,a,(a+b)/2,2*u+1,val);
		add(l,r,(a+b)/2,b,2*u+2,val);

		dat2[u]=max(dat2[2*u+1]+dat1[2*u+1],dat2[2*u+2]+dat1[2*u+2]);
	}

	lint query_max(int l,int r,int a,int b,int u){
		if(b<=l || r<=a) return 0;
		if(l<=a && b<=r) return dat1[u]+dat2[u];

		lint res1=query_max(l,r,a,(a+b)/2,2*u+1);
		lint res2=query_max(l,r,(a+b)/2,b,2*u+2);
		return max(res1,res2)+dat1[u];
	}

public:
	starry_sky_tree(int N){
		for(n=1;n<N;n*=2);
		dat1.assign(2*n,0);
		dat2.assign(2*n,0);
	}

	void add(int l,int r,lint val){ add(l,r,0,n,0,val); }

	lint query_max(int l,int r){ return query_max(l,r,0,n,0); }
};

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n-1);
	rep(i,n-1) scanf("%lld",&a[i]);

	starry_sky_tree SS(n-1);
	rep(i,n-1) SS.add(i,i+1,a[i]+3*(n-i-1));

	int q; scanf("%d",&q);
	rep(_,q){
		int l,r;
		lint d; scanf("%d%d%lld",&l,&r,&d); l--;
		SS.add(l,r,d);
		printf("%lld\n",SS.query_max(0,n-1));
	}

	return 0;
}
0