結果
| 問題 |
No.631 Noelちゃんと電車旅行
|
| コンテスト | |
| ユーザー |
SugarDragon5
|
| 提出日時 | 2018-08-09 20:33:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 515 ms / 2,000 ms |
| コード長 | 3,918 bytes |
| コンパイル時間 | 1,771 ms |
| コンパイル使用メモリ | 176,300 KB |
| 実行使用メモリ | 7,424 KB |
| 最終ジャッジ日時 | 2024-10-02 09:38:14 |
| 合計ジャッジ時間 | 9,213 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
template<typename Monoid,typename OperatorMonoid=Monoid>
struct LazySegTree{
//0-indexed 閉区間
using F=function<Monoid(Monoid,Monoid)>;
using G=function<Monoid(Monoid,OperatorMonoid)>;
using H=function<OperatorMonoid(OperatorMonoid,OperatorMonoid)>;
using P=function<OperatorMonoid(OperatorMonoid,int)>;
int size;
vector<Monoid> data;
vector<OperatorMonoid> lazy;
const F f; //要素同士の演算
const G g; //要素と作用素のマージ
const H h; //作用素同士のマージ
const P p; //作用素を下に降ろす
const Monoid M1; //単位元
const OperatorMonoid OM0; //作用素の単位元
LazySegTree(int n,const F f,const G g,const H h,const P p,const Monoid &M1,const OperatorMonoid OM0)
:f(f),g(g),h(h),p(p),M1(M1),OM0(OM0){
size=1;
while(size<n)size<<=1;
data.assign(size*2-1,M1);
lazy.assign(size*2-1,OM0);
}
void set(int k,const Monoid &x){
//kをxに初期化
//buildを忘れずに行うこと
data[k+size-1]=x;
}
void build(){
//構築 O(N)
for(int k=size-2;k>=0;k--){
data[k]=f(data[2*k+1],data[2*k+2]);
}
}
void propagate(int k,int len){
//長さlenのkから下へ伝播
if(lazy[k]!=OM0){
if(k<size-1){
lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
lazy[2*k+2]=h(lazy[2*k+2],lazy[k]);
}
data[k]=g(data[k],p(lazy[k],len));
lazy[k]=OM0;
}
}
Monoid update(int a,int b,const OperatorMonoid &x,int k,int l,int r){
propagate(k,r-l+1);
if(r<a||b<l){ //範囲外
return data[k];
}else if(a<=l&&b>=r){ //内部
lazy[k]=h(lazy[k],x);
propagate(k,r-l+1);
return data[k];
}else{
return data[k]=f(update(a,b,x,2*k+1,l,(l+r)/2),
update(a,b,x,2*k+2,(l+r)/2+1,r));
}
}
Monoid update(int a,int b,const OperatorMonoid &x){
//[a,b]をxに変更
return update(a,b,x,0,0,size-1);
}
Monoid query(int a,int b,int k,int l,int r){
propagate(k,r-l+1);
if(r<a||b<l){
return M1;
}else if(a<=l&&b>=r){
return data[k];
}else{
return f(query(a,b,2*k+1,l,(l+r)/2),
query(a,b,2*k+2,(l+r)/2+1,r));
}
}
Monoid query(int a,int b){
return query(a,b,0,0,size-1);
}
Monoid operator[](const int &k){
return query(k,k);
}
void debug(){
for(int i=0;i<size;i++){
if(i)cerr<<" ";cerr<<(*this)[i];
}cerr<<endl;
}
};
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
int n;
cin>>n;
n--;
auto f=[](ll a,ll b){return max(a,b);};
auto g=[](ll a,ll b){return a+b;};
auto p=[](ll a,ll b){return a;};
LazySegTree<ll> tr(n,f,g,g,p,0,0);
REP(i,n){
ll x;
cin>>x;
tr.set(i,x+(n-i)*3);
}
tr.build();
int m;
cin>>m;
REP(i,m){
int l,r;ll d;
cin>>l>>r>>d;
l--;r--;
tr.update(l,r,d);
cout<<tr.query(0,n-1)<<endl;
}
return 0;
}
SugarDragon5