結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー |
![]() |
提出日時 | 2018-07-17 17:22:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 2,184 bytes |
コンパイル時間 | 1,449 ms |
コンパイル使用メモリ | 166,608 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-10-02 09:37:57 |
合計ジャッジ時間 | 7,393 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ull mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; template <class T> class Lazy_Segment_Tree{ private: int n; vector<T> date,lazy; void Set_Lazy(int k,T x){ date[k]+=x; lazy[k]+=x; } void Push(int k){ Set_Lazy(k*2+1,lazy[k]); Set_Lazy(k*2+2,lazy[k]); lazy[k]=0; } void Fix(int k){ date[k]=max(date[k*2+1],date[k*2+2]); } void Add_func(int a,int b,int k,int l,int r,T x){ if(r<=a||b<=l) return; if(a<=l&&r<=b){ Set_Lazy(k,x); return; } Push(k); int m=(l+r)/2; Add_func(a,b,k*2+1,l,m,x); Add_func(a,b,k*2+2,m,r,x); Fix(k); } void Update_func(int I,int k,int l,int r,T x){ if(r<=I||I<l) return; if(l==I&&r-l==1){ date[k]=x; lazy[k]=x; return; } Push(k); int m=(l+r)/2; Update_func(I,k*2+1,l,m,x); Update_func(I,k*2+2,m,r,x); Fix(k); } T Query_func(int a,int b,int k,int l,int r){ if(r<=a||b<=l) return -INF; if(a<=l&&r<=b) return date[k]; Push(k); int m=(l+r)/2; T vl=Query_func(a,b,k*2+1,l,m); T vr=Query_func(a,b,k*2+2,m,r); return max(vl,vr); } public: Lazy_Segment_Tree(int n_){ n=1; while(n<n_) n*=2; date=lazy=vector<T>(2*n-1,-INF); } void Add(int a,int b,T x){ Add_func(a,b,0,0,n,x); } void Update(int k,T x){ Update_func(k,0,0,n,x); } T Query(int a,int b){ return Query_func(a,b,0,0,n); } }; ll n,m; int main(){ cin>>n; Lazy_Segment_Tree<ll> st(n); for(int i=0;i<n-1;i++){ int A; cin>>A; st.Update(i,A-3*i); } cin>>m; for(int i=0;i<m;i++){ int l,r,A; cin>>l>>r>>A; st.Add(l-1,r,A); cout<<3*n+st.Query(0,n-1)-3<<endl; } }