結果

問題 No.2333 Slime Structure
ユーザー m_99m_99
提出日時 2023-05-28 15:35:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 529 ms / 3,000 ms
コード長 2,203 bytes
コンパイル時間 4,201 ms
コンパイル使用メモリ 234,624 KB
実行使用メモリ 53,448 KB
最終ジャッジ日時 2023-08-27 12:30:15
合計ジャッジ時間 21,151 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 239 ms
27,300 KB
testcase_03 AC 306 ms
31,220 KB
testcase_04 AC 345 ms
31,032 KB
testcase_05 AC 259 ms
28,740 KB
testcase_06 AC 377 ms
32,436 KB
testcase_07 AC 458 ms
51,656 KB
testcase_08 AC 456 ms
53,008 KB
testcase_09 AC 451 ms
52,252 KB
testcase_10 AC 459 ms
52,840 KB
testcase_11 AC 470 ms
52,424 KB
testcase_12 AC 456 ms
52,040 KB
testcase_13 AC 455 ms
51,784 KB
testcase_14 AC 452 ms
52,220 KB
testcase_15 AC 446 ms
51,584 KB
testcase_16 AC 449 ms
53,448 KB
testcase_17 AC 450 ms
51,572 KB
testcase_18 AC 454 ms
53,052 KB
testcase_19 AC 448 ms
51,680 KB
testcase_20 AC 454 ms
52,280 KB
testcase_21 AC 454 ms
52,532 KB
testcase_22 AC 528 ms
51,816 KB
testcase_23 AC 525 ms
51,956 KB
testcase_24 AC 527 ms
52,260 KB
testcase_25 AC 525 ms
52,216 KB
testcase_26 AC 529 ms
51,956 KB
testcase_27 AC 527 ms
51,516 KB
testcase_28 AC 529 ms
51,764 KB
testcase_29 AC 529 ms
51,656 KB
testcase_30 AC 529 ms
52,648 KB
testcase_31 AC 525 ms
52,224 KB
testcase_32 AC 438 ms
52,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

struct Data{
	long long suf = -Inf64,pre = -Inf64,all = 0,max = -Inf64;
};

Data op(Data a,Data b){

	if(a.suf==-Inf64)return b;
	if(b.suf==-Inf64)return a;

	a.max = max({a.max,b.max,a.suf,b.suf,a.pre,b.pre,a.suf + b.pre});

	a.pre = max({a.all + b.pre,a.pre});

	a.suf = max({b.suf,a.suf + b.all});

	a.all += b.all;
	a.max = max({a.max,a.pre,a.suf,a.all});

	return a;
}

Data e(){
	return Data();
}

int main(){
	
	int N;
	cin>>N;
	
	vector<long long> ts(1,0);
	vector<long long> a(N),b(N);
	long long cur = 0;
	rep(i,N){
		cin>>a[i]>>b[i];
		cur += b[i];
		ts.push_back(cur);
	}
	int Q;
	cin>>Q;
	vector<long long> t(Q),x(Q),y(Q);
	rep(i,Q){
		cin>>t[i]>>x[i]>>y[i];
		x[i]--;
		if(t[i]==1){
			ts.push_back(x[i]);
			ts.push_back(x[i]+1);
		}
		else{
			ts.push_back(x[i]);
			ts.push_back(y[i]);
		}
	}
	sort(ts.begin(),ts.end());
	ts.erase(unique(ts.begin(),ts.end()),ts.end());
	cur = 0;
	segtree<Data,op,e> seg(ts.size());
	rep(i,N){
		long long l = distance(ts.begin(),lower_bound(ts.begin(),ts.end(),cur));
		
		while(ts[l]!=cur+b[i]){
			long long haba = ts[l+1] - ts[l];
			Data d;
			d.all = (long long)a[i] * haba;
			d.pre = max((long long)a[i],d.all);
			d.suf = max((long long)a[i],d.all);
			d.max = max(d.pre,d.suf);
			seg.set(l,d);
			l++;
		}
		cur += b[i];
	}
	/*cout<<"hoge"<<endl;
	rep(i,ts.size()-1){
		cout<<ts[0]<<','<<ts[i+1]<<','<<seg.prod(0,i+1).pre<<','<<seg.prod(0,i+1).suf<<','<<seg.prod(0,i+1).max<<endl;
		//return 0;
	}
	*/
	
	rep(i,Q){
		if(t[i]==1){
			int l = distance(ts.begin(),lower_bound(ts.begin(),ts.end(),x[i]));
			Data d;
			d.all = y[i] * 1;
			d.pre = max((long long)y[i],d.all);
			d.suf = max((long long)y[i],d.all);
			d.max = max(d.pre,d.suf);
			seg.set(l,d);
		}
		else{
			int l = distance(ts.begin(),lower_bound(ts.begin(),ts.end(),x[i]));
			int r = distance(ts.begin(),lower_bound(ts.begin(),ts.end(),y[i]));
			
			
			Data ans = seg.prod(l,r);
			cout<<ans.max<<endl;
		}
	}
	return 0;
}
0