結果

問題 No.631 Noelちゃんと電車旅行
ユーザー 👑 kmjpkmjp
提出日時 2018-01-05 21:36:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,709 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 167,688 KB
実行使用メモリ 35,968 KB
最終ジャッジ日時 2024-04-10 07:41:15
合計ジャッジ時間 6,777 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 222 ms
35,872 KB
testcase_01 AC 271 ms
35,912 KB
testcase_02 AC 283 ms
35,968 KB
testcase_03 AC 275 ms
35,968 KB
testcase_04 AC 271 ms
35,908 KB
testcase_05 AC 277 ms
35,844 KB
testcase_06 AC 121 ms
35,928 KB
testcase_07 AC 70 ms
35,868 KB
testcase_08 AC 206 ms
35,912 KB
testcase_09 AC 244 ms
35,968 KB
testcase_10 AC 174 ms
35,928 KB
testcase_11 AC 156 ms
35,964 KB
testcase_12 AC 189 ms
35,908 KB
testcase_13 AC 187 ms
35,916 KB
testcase_14 AC 100 ms
35,864 KB
testcase_15 AC 160 ms
35,936 KB
testcase_16 AC 16 ms
35,828 KB
testcase_17 AC 15 ms
35,928 KB
testcase_18 AC 17 ms
35,916 KB
testcase_19 AC 16 ms
35,868 KB
testcase_20 AC 16 ms
35,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int T[101010];

static ll const def=-1LL<<40;
template<class V,int NV> class SegTree_3 {
public:
	vector<V> val, ma;
	SegTree_3(){
		int i;
		val.resize(NV*2,0); ma.resize(NV*2,0);
		FOR(i,NV) val[i+NV]=ma[i+NV]=def;
		for(i=NV-1;i>=1;i--) ma[i]=max(ma[2*i],ma[2*i+1]);
	};
	
	V getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return ma[k];
		return val[k]+max(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	
	void update(int x,int y, V v,int l=0,int r=NV,int k=1) {
		if(l>=r) return;
		if(x<=l && r<=y) {
			val[k]+=v;
			ma[k]+=v;
		}
		else if(l < y && x < r) {
			update(x,y,v,l,(l+r)/2,k*2);
			update(x,y,v,(l+r)/2,r,k*2+1);
			ma[k]=val[k]+max(ma[k*2],ma[k*2+1]);
		}
	}
};

SegTree_3<ll,1<<20> st;
int M,L,R,X;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x;
		x-=i*3;
		st.update(i,i+1,(1LL<<40)+x);
	}
	cin>>M;
	while(M--) {
		cin>>L>>R>>X;
		st.update(L-1,R,X);
		ll ma=st.getval(0,N-1);
		cout<<(ma+(N-1)*3)<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0