結果

問題 No.2333 Slime Structure
ユーザー kotatsugamekotatsugame
提出日時 2023-05-28 15:06:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 3,000 ms
コード長 1,708 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 81,740 KB
実行使用メモリ 63,344 KB
最終ジャッジ日時 2023-08-27 11:27:10
合計ジャッジ時間 12,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,012 KB
testcase_01 AC 1 ms
5,020 KB
testcase_02 AC 145 ms
32,212 KB
testcase_03 AC 189 ms
36,356 KB
testcase_04 AC 211 ms
36,184 KB
testcase_05 AC 157 ms
33,564 KB
testcase_06 AC 235 ms
38,116 KB
testcase_07 AC 280 ms
61,176 KB
testcase_08 AC 279 ms
61,324 KB
testcase_09 AC 279 ms
62,096 KB
testcase_10 AC 297 ms
61,696 KB
testcase_11 AC 278 ms
61,988 KB
testcase_12 AC 282 ms
61,612 KB
testcase_13 AC 296 ms
61,956 KB
testcase_14 AC 278 ms
62,140 KB
testcase_15 AC 277 ms
61,896 KB
testcase_16 AC 291 ms
62,108 KB
testcase_17 AC 276 ms
63,344 KB
testcase_18 AC 281 ms
62,224 KB
testcase_19 AC 277 ms
62,676 KB
testcase_20 AC 275 ms
61,820 KB
testcase_21 AC 266 ms
62,212 KB
testcase_22 AC 294 ms
62,092 KB
testcase_23 AC 303 ms
62,404 KB
testcase_24 AC 293 ms
62,056 KB
testcase_25 AC 292 ms
62,868 KB
testcase_26 AC 293 ms
61,832 KB
testcase_27 AC 293 ms
61,832 KB
testcase_28 AC 295 ms
61,764 KB
testcase_29 AC 298 ms
62,208 KB
testcase_30 AC 294 ms
61,828 KB
testcase_31 AC 296 ms
62,980 KB
testcase_32 AC 253 ms
61,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
#include<atcoder/segtree>
using namespace std;
struct dat{
	long sum,L,R,M;
	bool e;
};
dat op(dat l,dat r)
{
	if(l.e)return r;
	if(r.e)return l;
	dat ret;
	ret.sum=l.sum+r.sum;
	ret.L=max(l.L,l.sum+r.L);
	ret.R=max(r.R,r.sum+l.R);
	ret.M=max(max(l.M,r.M),max(max(l.R,r.L),l.R+r.L));
	ret.e=false;
	return ret;
}
dat e(){return(dat){0L,0L,0L,0L,true};}
int N,Q;
int A[1<<17];
long B[1<<17];
int Op[1<<17];
long T1[1<<17],T2[1<<17];
int main()
{
	cin>>N;
	vector<long>dv;
	dv.push_back(0L);
	for(int i=0;i<N;i++)
	{
		cin>>A[i]>>B[i];
		long t=dv.back()+B[i];
		B[i]=t;
		dv.push_back(t);
	}
	cin>>Q;
	for(int i=0;i<Q;i++)
	{
		cin>>Op[i]>>T1[i]>>T2[i];
		T1[i]--;
		if(Op[i]==1)
		{
			dv.push_back(T1[i]);
			dv.push_back(T1[i]+1);
		}
		else
		{
			dv.push_back(T1[i]);
			dv.push_back(T2[i]);
		}
	}
	sort(dv.begin(),dv.end());
	dv.erase(unique(dv.begin(),dv.end()),dv.end());
	vector<dat>init(dv.size()-1);
	int idx=0;
	for(int i=0;i+1<dv.size();i++)
	{
		//dv[i+1]<=B[idx]
		while(B[idx]<dv[i+1])idx++;
		//cout<<dv[i]<<"->"<<dv[i+1]<<" : "<<A[idx]<<" "<<B[idx]<<endl;
		init[i].sum=A[idx]*(dv[i+1]-dv[i]);
		init[i].L=init[i].R=init[i].M=A[idx]>=0?init[i].sum:A[idx];
		init[i].e=false;
	}
	atcoder::segtree<dat,op,e>seg(init);
	for(int i=0;i<Q;i++)
	{
		if(Op[i]==1)
		{
			int j=lower_bound(dv.begin(),dv.end(),T1[i])-dv.begin();
			assert(dv[j+1]==T1[i]+1);
			seg.set(j,(dat){T2[i],T2[i],T2[i],T2[i],false});
		}
		else
		{
			int l=lower_bound(dv.begin(),dv.end(),T1[i])-dv.begin();
			int r=lower_bound(dv.begin(),dv.end(),T2[i])-dv.begin();
			assert(dv[l]==T1[i]&&dv[r]==T2[i]);
			cout<<seg.prod(l,r).M<<"\n";
		}
	}
}
0