結果

問題 No.631 Noelちゃんと電車旅行
ユーザー Lepton_sLepton_s
提出日時 2018-01-05 22:15:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 2,471 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 100,144 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-10 07:42:06
合計ジャッジ時間 7,412 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 275 ms
6,812 KB
testcase_01 AC 374 ms
7,296 KB
testcase_02 AC 377 ms
7,552 KB
testcase_03 AC 377 ms
7,296 KB
testcase_04 AC 389 ms
7,296 KB
testcase_05 AC 381 ms
7,296 KB
testcase_06 AC 149 ms
6,940 KB
testcase_07 AC 85 ms
6,940 KB
testcase_08 AC 279 ms
7,424 KB
testcase_09 AC 330 ms
6,944 KB
testcase_10 AC 230 ms
7,296 KB
testcase_11 AC 203 ms
6,940 KB
testcase_12 AC 256 ms
7,552 KB
testcase_13 AC 247 ms
6,944 KB
testcase_14 AC 122 ms
6,944 KB
testcase_15 AC 202 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

struct rmq {
	int seg_n;
	vector<ll> data, datb;
	void init(int n, ll initial_value = INF){
		seg_n = 1;
		while(seg_n<n) seg_n<<=1;
		data = vector<ll>(seg_n*2-1, 0);
		datb = vector<ll>(seg_n*2-1, 0);
	}

	// v[k] <- a
	/*void update(int k, ll a){
		k += seg_n - 1;
		dat[k] = a;
		while(k>0){
			k = (k-1)/2;
			dat[k] = min(dat[k*2+1], dat[k*2+2]);
		}
	}*/

	// min(v[a], v[a+1],..., v[b-1])
	// to use: query(a, b);
	ll rmin(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return INF;
		if(a <= l && r <= b) return data[k]+datb[k];
		return min(rmin(a, b, k*2+1, l, (l+r)/2), rmin(a, b, k*2+2, (l+r)/2, r))+data[k];
	}

	ll rmin(int a, int b){
		return rmin(a, b, 0, 0, seg_n);
	}

	void radd(int a, int b, ll x, int k, int l, int r){
		if(r <= a || b <= l) return;//return INF;
		if(a <= l && r <= b){
			data[k] += x;
			return;
			//return data[k]+datb[k];
		} else {
			radd(a, b, x, k*2+1, l, (l+r)/2);
			radd(a, b, x, k*2+2, (l+r)/2, r);
			datb[k] = min(datb[k*2+1]+data[k*2+1], datb[k*2+2]+data[k*2+2]);
		}
	}

	void radd(int a, int b, ll x){
		radd(a, b, x, 0, 0, seg_n);
	}
};
int main(){
	ll n;
	cin>>n;
	rmq x;
	x.init(n-1);
	rep(i, n-1){
		ll a;
		cin>>a;
		a += 3*(n-i-1);
		x.radd(i, i+1, -a);
	}
	ll m;
	cin>>m;
	rep(i, m){
		ll l, r, d;
		cin>>l>>r>>d;
		l--;
		x.radd(l, r, -d);
		ll res = x.rmin(0, n-1);
		cout<<-res<<endl;
	}
	return 0;
}
0