結果
| 問題 |
No.631 Noelちゃんと電車旅行
|
| コンテスト | |
| ユーザー |
hashiryo
|
| 提出日時 | 2019-05-31 10:44:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 354 ms / 2,000 ms |
| コード長 | 2,735 bytes |
| コンパイル時間 | 1,549 ms |
| コンパイル使用メモリ | 166,368 KB |
| 実行使用メモリ | 8,064 KB |
| 最終ジャッジ日時 | 2024-10-02 09:42:22 |
| 合計ジャッジ時間 | 7,569 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;
template <typename T,typename E>
class LazySegmentTree{
private:
using F = function<T(T,T)>;
using G = function<T(T,E)>;
using H = function<E(E,E)>;
int n,height;
F f;
G g;
H h;
T ti;
E ei;
vector<T> dat;
vector<E> laz;
inline T reflect(int k){
return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
}
inline void eval(int k){
if(laz[k]==ei) return;
laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
dat[k]=reflect(k);
laz[k]=ei;
}
inline void thrust(int k){
for(int i=height;i;i--) eval(k>>i);
}
inline void recalc(int k){
while(k>>=1)
dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
}
public:
LazySegmentTree(F f,G g,H h,T ti,E ei):
f(f),g(g),h(h),ti(ti),ei(ei){}
void init(int n_){
n=1;height=0;
while(n<n_) n<<=1,height++;
dat.assign(2*n,ti);
laz.assign(2*n,ei);
}
void build(const vector<T> &v){
int n_=v.size();
init(n_);
for(int i=0;i<n_;i++) dat[n+i]=v[i];
for(int i=n-1;i;i--)
dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
}
void update(int a,int b,E x){
thrust(a+=n);
thrust(b+=n-1);
for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
if(l&1) laz[l]=h(laz[l],x),l++;
if(r&1) --r,laz[r]=h(laz[r],x);
}
recalc(a);
recalc(b);
}
void set_val(int a,T x){
thrust(a+=n);
dat[a]=x;laz[a]=ei;
recalc(a);
}
T query(int a,int b){
thrust(a+=n);
thrust(b+=n-1);
T vl=ti,vr=ti;
for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
if(l&1) vl=f(vl,reflect(l++));
if(r&1) vr=f(reflect(--r),vr);
}
return f(vl,vr);
}
T operator[](const int k){return query(k,k+1);}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;cin>>N;N--;
vll T(N);
for(ll i=0;i<N;i++){
cin>>T[i];
}
LazySegmentTree<ll,ll> seg([](ll a,ll b){return max(a,b);},[](ll a,ll b){return a+b;},[](ll a,ll b){return a+b;},0,0);
seg.build(T);
for(ll i=0;i<N;i++){
seg.update(0,N-i,3);
}
ll M;cin>>M;
for(ll i=0;i<M;i++){
ll L,R,D;cin>>L>>R>>D;L--;R--;
seg.update(L,R+1,D);
cout<<seg.query(0,N)<<endl;
}
return 0;
}
hashiryo