結果

問題 No.1234 典型RMQ
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2017-04-26 23:47:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,138 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 165,748 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-27 06:33:32
合計ジャッジ時間 8,499 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
using ll = long long;
constexpr ll ten(int n){return n==0?1:10*ten(n-1);}
const int B=350;
const ll MX=ten(15);
int n,q;
ll val[B][B],ad[B],mi[B];
void push(int i){
	ll ma=ten(18);
	rep(j,B)if(i*B+j<n)ma=min(ma,val[i][j]);
	mi[i]=ma;
}

void add(int l,int r,int x){
	int lx=l/B,ly=l%B,rx=r/B,ry=r%B;
	if(lx!=rx){
		for(;ly<B;ly++)val[lx][ly]+=x;
		push(lx);
		lx++;ly=0;
		for(;lx<rx;lx++)ad[lx]+=x;
	}
	for(;ly<ry;ly++)val[rx][ly]+=x;
	push(rx);
}
ll get(int l,int r){
	int lx=l/B,ly=l%B,rx=r/B,ry=r%B;
	ll v=ten(18);
	if(lx!=rx){
		for(;ly<B;ly++)v=min(v,val[lx][ly]+ad[lx]);
		lx++;ly=0;
		for(;lx<rx;lx++)v=min(v,mi[lx]+ad[lx]);
	}
	for(;ly<ry;ly++)v=min(v,val[rx][ly]+ad[rx]);
	return v;
}
int main(){
	cin>>n;
	assert(1<=n&&n<=ten(5));
	rep(i,n){
		ll x;
		cin>>x;
		assert(-ten(10)<=x&&x<=ten(10));
	}
	rep(i,B)push(i);
	cin>>q;
	assert(1<=q&&q<=ten(5));
	rep(i,q){
		int k,l,r,c;
		cin>>k>>l>>r>>c;
		assert(k==1||k==2);
		assert(1<=l&&l<=r&&r<=n);
		assert(-ten(4)<=c&&c<=ten(4));
		l--;
		if(k==1)add(l,r,c);
		else cout<<get(l,r)<<endl;

	}
}
0