結果
| 問題 |
No.631 Noelちゃんと電車旅行
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-10-21 12:23:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 112 ms / 2,000 ms |
| コード長 | 1,530 bytes |
| コンパイル時間 | 1,749 ms |
| コンパイル使用メモリ | 165,944 KB |
| 実行使用メモリ | 13,284 KB |
| 最終ジャッジ日時 | 2025-10-21 12:23:59 |
| 合計ジャッジ時間 | 6,029 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000010;
const int mod=998244353;
int n,q;
int a[N];
int l,r,x;
struct SegmentTree{
int t[N<<2];
int lazy[N<<2];
int ls(int p){return p<<1;}
int rs(int p){return p<<1|1;}
void push_up(int p){
t[p]=max(t[ls(p)],t[rs(p)]);
return;
}
void build(int l,int r,int p){
if(l==r){
t[p]=a[l]+(n-l+1)*3;
return;
}
int mid=(l+r)>>1;
build(l,mid,ls(p));
build(mid+1,r,rs(p));
push_up(p);
return;
}
void addlazy(int p,int x){
t[p]+=x;
lazy[p]+=x;
return;
}
void push_down(int p){
if(!lazy[p])return;
addlazy(ls(p),lazy[p]);
addlazy(rs(p),lazy[p]);
lazy[p]=0;
return;
}
void update(int L,int R,int x,int l,int r,int p){
if(L<=l&&r<=R){
addlazy(p,x);
return;
}
push_down(p);
int mid=(l+r)>>1;
if(L<=mid)update(L,R,x,l,mid,ls(p));
if(R>mid)update(L,R,x,mid+1,r,rs(p));
push_up(p);
return;
}
// int query(int L,int R,int l,int r,int p){
// if(L<=l&&r<=R)return t[p];
// push_down(p);
// int mid=(l+r)>>1;
// int res=0;
// if(L<=mid)res=max(res,query(L,R,l,mid,ls(p)));
// if(R>mid)res=max(res,query(L,R,mid+1,r,rs(p)));
// push_up(p);
// return res;
// }
}T;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("onduty.in","r",stdin);
// freopen("onduty.out","w",stdout);
cin>>n;
n--;
for(int i=1;i<=n;i++)cin>>a[i];
T.build(1,n,1);
cin>>q;
while(q--){
cin>>l>>r>>x;
T.update(l,r,x,1,n,1);
cout<<T.t[1]<<"\n";
}
return 0;
}
/*
*/
vjudge1