結果

問題 No.631 Noelちゃんと電車旅行
ユーザー chocoruskchocorusk
提出日時 2018-12-14 09:30:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,627 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 95,480 KB
実行使用メモリ 7,372 KB
最終ジャッジ日時 2024-04-10 07:56:06
合計ジャッジ時間 7,539 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
6,812 KB
testcase_01 AC 416 ms
7,372 KB
testcase_02 AC 414 ms
7,248 KB
testcase_03 AC 420 ms
7,248 KB
testcase_04 AC 419 ms
7,116 KB
testcase_05 AC 425 ms
7,124 KB
testcase_06 AC 162 ms
6,940 KB
testcase_07 AC 95 ms
6,940 KB
testcase_08 AC 308 ms
6,940 KB
testcase_09 AC 361 ms
6,940 KB
testcase_10 AC 257 ms
6,992 KB
testcase_11 AC 231 ms
6,944 KB
testcase_12 AC 296 ms
6,988 KB
testcase_13 AC 267 ms
6,944 KB
testcase_14 AC 122 ms
6,944 KB
testcase_15 AC 224 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MAX_N=1<<17;
const ll INF=1e16;
ll mx[2*MAX_N-1], part[2*MAX_N-1];
bool mada[2*MAX_N-1];
int m;
void init(int n){
    m=1;
    while(m<n) m*=2;
}
void eval(int k, int l, int r){
    if(mada[k]){
        mx[k]+=part[k];
        if(k<m-1){
            part[2*k+1]+=part[k];
            part[2*k+2]+=part[k];
			mada[2*k+1]=1; mada[2*k+2]=1;
        }
        mada[k]=0;
		part[k]=0;
    }
}
void add(int a, int b, ll x, int k, int l, int r){
    eval(k, l, r);
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){
        part[k]=x;
		mada[k]=1;
        eval(k, l, r);
    }else{
        add(a, b, x, k*2+1, l, (l+r)/2);
        add(a, b, x, k*2+2, (l+r)/2, r);
        mx[k]=max(mx[2*k+1], mx[2*k+2]);
    }
}
ll find(int a, int b, int k, int l, int r){
    eval(k, l, r);
    if(b<=l || r<=a){
        return -INF;
    }
    if(a<=l && r<=b){
        return mx[k];
    }else{
        return max(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
    }
}
int main()
{
	int n;
	cin>>n;
	init(n);
	for(int i=1; i<n; i++){
		ll t; cin>>t;
		add(i, i+1, t-3*(i-1), 0, 0, m);
	}
	int M;
	cin>>M;
	for(int i=0; i<M; i++){
		int l, r; ll d;
		cin>>l>>r>>d;
		add(l, r+1, d, 0, 0, m);
		cout<<find(0, n, 0, 0, m)+3*(n-1)<<endl;
	}
	return 0;
}
0