結果

問題 No.631 Noelちゃんと電車旅行
コンテスト
ユーザー fura
提出日時 2020-10-16 17:07:26
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 828 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,418 ms
コンパイル使用メモリ 212,208 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-14 12:33:16
合計ジャッジ時間 5,019 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

template<class G>
class Fenwick_tree_dual{
	vector<G> a;
public:
	Fenwick_tree_dual(int n):a(n){}
	void add(int l,int r,const G& val){
		if(l==0){
			for(;r>0;r-=r&-r) a[r-1]+=val;
			return;
		}
		add(0,r,val);
		add(0,l,-val);
	}
	G sum(int i)const{
		G res{};
		for(i++;i<=a.size();i+=i&-i) res+=a[i-1];
		return res;
	}
};

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

	lint t=0;
	for(int i=1;i<n;i++){
		t=max(a[i],t)+3;
	}

	Fenwick_tree_dual<lint> F(n-1);
	rep(i,n-1) F.add(i,i+1,a[i]);

	int q; scanf("%d",&q);
	rep(_,q){
		int l,r;
		lint d; scanf("%d%d%lld",&l,&r,&d); l--;
		F.add(l,r,d);
		t=max(t,F.sum(l)+3*(n-l-1));
		printf("%lld\n",t);
	}

	return 0;
}
0