結果

問題 No.1234 典型RMQ
ユーザー furafura
提出日時 2020-10-20 16:44:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,352 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 200,564 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-04-26 11:44:44
合計ジャッジ時間 6,196 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 96 ms
5,888 KB
testcase_07 AC 70 ms
5,376 KB
testcase_08 AC 103 ms
6,272 KB
testcase_09 AC 84 ms
5,376 KB
testcase_10 AC 101 ms
6,016 KB
testcase_11 AC 90 ms
6,016 KB
testcase_12 AC 82 ms
5,376 KB
testcase_13 AC 74 ms
5,376 KB
testcase_14 AC 85 ms
5,376 KB
testcase_15 AC 81 ms
5,376 KB
testcase_16 AC 99 ms
6,144 KB
testcase_17 AC 83 ms
5,376 KB
testcase_18 AC 63 ms
5,376 KB
testcase_19 AC 102 ms
6,272 KB
testcase_20 AC 75 ms
6,144 KB
testcase_21 AC 96 ms
5,888 KB
testcase_22 AC 87 ms
6,144 KB
testcase_23 AC 88 ms
6,144 KB
testcase_24 AC 85 ms
6,272 KB
testcase_25 AC 89 ms
6,144 KB
testcase_26 AC 86 ms
6,144 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T>
class starry_sky_tree{
	int sz;
	vector<T> seg;

	void maintain(int u){
		if(1<=u && u<sz){
			T mx=std::max(seg[2*u],seg[2*u+1]);
			seg[u]+=mx;
			seg[2*u  ]-=mx;
			seg[2*u+1]-=mx;
		}
	}
	T max(int l,int r,int a,int b,int u,T cum)const{
		if(b<=l || r<=a) return numeric_limits<T>::min();
		if(l<=a && b<=r) return cum+seg[u];
		T lmax=max(l,r,a,(a+b)/2,2*u  ,cum+seg[u]);
		T rmax=max(l,r,(a+b)/2,b,2*u+1,cum+seg[u]);
		return std::max(lmax,rmax);
	}
public:
	starry_sky_tree(int n){
		for(sz=1;sz<n;sz<<=1);
		seg.assign(2*sz,T());
	}
	void add(int l,int r,const T& val){
		int a,b;
		for(a=l+sz,b=r+sz;a<b;a>>=1,b>>=1){
			if(a&1){ seg[a]+=val; a++; }
			if(b&1){ b--; seg[b]+=val; }
			maintain((a-1)>>1);
			maintain(b>>1);
		}
		for(int u=a-1;u>=1;u>>=1) maintain(u);
		for(int u= b ;u>=1;u>>=1) maintain(u);
	}
	T max(int l,int r)const{ return max(l,r,0,sz,1,0); }
};

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	starry_sky_tree<lint> SS(n);
	rep(i,n) SS.add(i,i+1,-a[i]);

	int q; scanf("%d",&q);
	rep(_,q){
		int type,l,r,c; scanf("%d%d%d%d",&type,&l,&r,&c); l--;
		if(type==1){
			SS.add(l,r,-c);
		}
		else{
			printf("%lld\n",-SS.max(l,r));
		}
	}

	return 0;
}
0