結果

問題 No.631 Noelちゃんと電車旅行
コンテスト
ユーザー 王源成
提出日時 2025-10-22 21:31:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,048 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 195,020 KB
実行使用メモリ 10,540 KB
最終ジャッジ日時 2025-10-22 21:31:45
合計ジャッジ時間 5,560 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10,T=3;
int n,a[N];
int mx[N<<2],lazy[N<<2];
#define mid (l+r)/2
#define ls u<<1
#define rs u<<1|1
inline void pushup(int u){
	mx[u]=max(mx[ls],mx[rs]);
}
inline void pushdown(int u){
	mx[ls]+=lazy[u];
	lazy[ls]+=lazy[u];
	mx[rs]+=lazy[u];
	lazy[rs]+=lazy[u];
	lazy[u]=0;
}
void build(int u,int l,int r){
	lazy[u]=0; 
	if(l==r){
		mx[u]=a[l]+(n-l)*T;
		return;
	}
	build(ls,l,mid);
	build(rs,mid+1,r);
	pushup(u);
	return;
}
void update(int u,int l,int r,int ql,int qr,int d){
	if(ql<=l&&r<=qr){
		mx[u]+=d;
		lazy[u]+=d;
		return;
	}
	if(qr<l||r<ql) return;
	pushdown(u);
	update(ls,l,mid,ql,qr,d);
	update(rs,mid+1,r,ql,qr,d);
	pushup(u);
	return;
}

signed main(){
	//freopen("delay.in","r",stdin);
	//freopen("delay.out","w",stdout); 
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n-1;i++) cin>>a[i];
	build(1,1,n-1);
	int q;cin>>q;
	while(q--){
		int l,r,d;cin>>l>>r>>d;
		update(1,1,n-1,l,r,d);
		cout<<mx[1]<<'\n';
	}
	return 0;
}
0