結果
| 問題 |
No.631 Noelちゃんと電車旅行
|
| コンテスト | |
| ユーザー |
moko_freedom
|
| 提出日時 | 2018-01-11 22:01:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,901 bytes |
| コンパイル時間 | 1,413 ms |
| コンパイル使用メモリ | 168,340 KB |
| 実行使用メモリ | 8,960 KB |
| 最終ジャッジ日時 | 2024-12-23 16:22:12 |
| 合計ジャッジ時間 | 6,856 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 21 |
ソースコード
#include <bits/stdc++.h>
//#include <math.h>
using namespace std;
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
struct edge {
int to, cost;
edge(int t,int c):to(t),cost(c) {}
};
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
//-----------------------------------------------------------------------------
struct LazySegTree {
private:
int n;
vector<ll> node,lazy;
public:
LazySegTree(vector<ll> v) {
int sz=(int)v.size();
n=1; while(n<sz) n*=2;
node.resize(2*n-1);
lazy.resize(2*n-1,0);
REP(i,sz) node[i+n-1]=v[i];
for(int i=n-2;i>=0;i--) node[i]=max(node[i*2+1],node[i*2+2]);
}
void eval(int k,int l,int r) {
if(lazy[k]!=0) {
node[k]+=lazy[k];
if(r-l>1) {
lazy[2*k+1]+=lazy[k]/2;
lazy[2*k+2]+=lazy[k]/2;
}
lazy[k]=0;
}
}
void add(int a,int b,ll x,int k=0,int l=0,int r=-1) {
if(r<0) r=n;
eval(k,l,r);
if(b<=l||r<=a) return;
if(a<=l&&r<=b) {
lazy[k]+=x;
eval(k,l,r);
}
else {
add(a,b,x,2*k+1,l,(l+r)/2);
add(a,b,x,2*k+2,(l+r)/2,r);
node[k]=max(node[2*k+1],node[2*k+2]);
}
}
ll getmax(int a,int b,int k=0,int l=0,int r=-1) {
if(r<0) r=n;
eval(k,l,r);
if(b<=l||r<=a) return -INF;
if(a<=l&&r<=b) return node[k];
ll vl=getmax(a,b,2*k+1,l,(l+r)/2);
ll vr=getmax(a,b,2*k+2,(l+r)/2,r);
return max(vr,vl);
}
};
int n,m;
vector<ll> t;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin>>n;
t.resize(n-1);
REP(i,n-1) {
cin>>t[i];t[i]+=3*(n-i-1);
}
LazySegTree seg(t);
cin>>m;
REP(i,m) {
int l,r;ll d;
cin>>l>>r>>d;
seg.add(l-1,r,d);
cout<<seg.getmax(0,n)<<endl;
}
return 0;
}
moko_freedom