結果

問題 No.855 ヘビの日光浴
ユーザー 👑 kmjpkmjp
提出日時 2019-07-27 02:58:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,853 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 183,100 KB
実行使用メモリ 38,868 KB
最終ジャッジ日時 2024-04-09 20:34:57
合計ジャッジ時間 12,750 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
36,028 KB
testcase_01 AC 13 ms
38,108 KB
testcase_02 AC 14 ms
36,100 KB
testcase_03 AC 13 ms
36,096 KB
testcase_04 WA -
testcase_05 AC 12 ms
36,064 KB
testcase_06 AC 13 ms
36,204 KB
testcase_07 AC 12 ms
36,208 KB
testcase_08 AC 12 ms
36,036 KB
testcase_09 AC 14 ms
36,000 KB
testcase_10 WA -
testcase_11 AC 13 ms
35,860 KB
testcase_12 AC 13 ms
36,068 KB
testcase_13 AC 13 ms
36,148 KB
testcase_14 WA -
testcase_15 AC 13 ms
36,204 KB
testcase_16 AC 13 ms
36,100 KB
testcase_17 AC 14 ms
38,232 KB
testcase_18 AC 13 ms
36,032 KB
testcase_19 AC 13 ms
35,864 KB
testcase_20 WA -
testcase_21 AC 13 ms
36,168 KB
testcase_22 AC 13 ms
36,176 KB
testcase_23 AC 13 ms
36,140 KB
testcase_24 AC 13 ms
36,152 KB
testcase_25 WA -
testcase_26 AC 13 ms
36,176 KB
testcase_27 AC 14 ms
38,232 KB
testcase_28 AC 13 ms
36,040 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 13 ms
36,028 KB
testcase_33 WA -
testcase_34 AC 15 ms
36,004 KB
testcase_35 AC 14 ms
36,032 KB
testcase_36 AC 13 ms
36,068 KB
testcase_37 AC 15 ms
36,196 KB
testcase_38 WA -
testcase_39 AC 14 ms
36,068 KB
testcase_40 WA -
testcase_41 AC 14 ms
36,140 KB
testcase_42 AC 12 ms
36,144 KB
testcase_43 AC 14 ms
38,104 KB
testcase_44 AC 15 ms
36,152 KB
testcase_45 AC 15 ms
36,152 KB
testcase_46 WA -
testcase_47 AC 14 ms
36,140 KB
testcase_48 AC 14 ms
36,144 KB
testcase_49 AC 14 ms
36,060 KB
testcase_50 AC 14 ms
36,212 KB
testcase_51 WA -
testcase_52 AC 14 ms
36,176 KB
testcase_53 AC 14 ms
36,216 KB
testcase_54 AC 13 ms
36,060 KB
testcase_55 AC 12 ms
38,100 KB
testcase_56 AC 14 ms
36,024 KB
testcase_57 AC 13 ms
35,992 KB
testcase_58 AC 13 ms
36,064 KB
testcase_59 AC 13 ms
36,212 KB
testcase_60 AC 14 ms
36,172 KB
testcase_61 AC 14 ms
36,140 KB
testcase_62 AC 14 ms
36,204 KB
testcase_63 AC 13 ms
36,136 KB
testcase_64 AC 12 ms
36,008 KB
testcase_65 AC 13 ms
36,068 KB
testcase_66 AC 13 ms
36,040 KB
testcase_67 AC 14 ms
36,208 KB
testcase_68 AC 13 ms
35,992 KB
testcase_69 AC 13 ms
36,096 KB
testcase_70 AC 13 ms
36,068 KB
testcase_71 AC 13 ms
36,104 KB
testcase_72 AC 13 ms
36,000 KB
testcase_73 AC 165 ms
36,992 KB
testcase_74 AC 161 ms
36,956 KB
testcase_75 AC 93 ms
36,640 KB
testcase_76 AC 326 ms
38,868 KB
testcase_77 AC 243 ms
37,468 KB
testcase_78 AC 378 ms
38,308 KB
testcase_79 AC 28 ms
36,280 KB
testcase_80 AC 32 ms
36,224 KB
testcase_81 AC 440 ms
38,536 KB
testcase_82 AC 477 ms
38,544 KB
testcase_83 AC 460 ms
38,736 KB
testcase_84 AC 467 ms
38,500 KB
testcase_85 AC 475 ms
38,492 KB
testcase_86 AC 441 ms
38,764 KB
testcase_87 AC 449 ms
38,564 KB
testcase_88 AC 434 ms
38,632 KB
testcase_89 AC 473 ms
38,708 KB
testcase_90 AC 469 ms
38,608 KB
testcase_91 AC 470 ms
38,736 KB
testcase_92 AC 474 ms
38,568 KB
testcase_93 AC 13 ms
36,172 KB
testcase_94 AC 305 ms
38,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V,int NV> class SegTree_max {
public:
	vector<V> val;
	static V const def=0;
	V comp(V l,V r){ return max(l,r);};
	
	SegTree_max(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=v;
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};

template<class V,int NV> class SegTree_min {
public:
	vector<V> val;
	static V const def=1<<30;
	V comp(V l,V r){ return min(l,r);};
	
	SegTree_min(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=v;
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};

SegTree_min<int,1<<20> SR,SD;
SegTree_max<int,1<<20> SL,ST;

int H,W,N,OH,OW;
int X[101010],Y[101010],L[101010];
vector<int> Xs,Ys;

int DL[101010];
int DR[101010];
int DT[101010];
int DD[101010];



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N;
	Xs.push_back(0);
	Xs.push_back(W+1);
	Ys.push_back(0);
	Ys.push_back(H+1);
	FOR(i,N) {
		cin>>X[i]>>Y[i]>>L[i];
		if(X[i]==0 || X[i]==W+1) Ys.push_back(Y[i]);
		else Xs.push_back(X[i]);
	}
	sort(ALL(Xs));
	sort(ALL(Ys));
	Xs.erase(unique(ALL(Xs)),Xs.end());
	Ys.erase(unique(ALL(Ys)),Ys.end());
	OW=W;
	OH=H;
	W=Xs.size();
	H=Ys.size();
	FOR(i,H) SR.update(i,DR[i]=OW+1);
	FOR(i,W) SD.update(i,DD[i]=OH+1);
	FOR(i,N) {
		if(X[i]==0 || X[i]==OW+1) {
			y=lower_bound(ALL(Ys),Y[i])-Ys.begin();
			if(X[i]==0) {
				int xt=W-1,xd=W-1;
				
				for(j=20;j>=0;j--) {
					if(ST.getval(0,xt-(1<<j)+1)>=Y[i]) xt-=1<<j;
					if(SD.getval(0,xd-(1<<j)+1)<=Y[i]) xd-=1<<j;
				}
				DL[y]+=L[i];
				if(min({Xs[xt],Xs[xd],DR[y]})<=DL[y]) {
					DL[y]=0;
					if(Xs[xt]<Xs[xd]&&Xs[xt]<DR[y]) ST.update(xt,DT[xt]=0);
					if(Xs[xd]<Xs[xt]&&Xs[xd]<DR[y]) SD.update(xd,DD[xd]=OH+1);
					if(DR[y]<Xs[xt]&&DR[y]<Xs[xd]) SR.update(y,DR[y]=OW+1);
				}
				SL.update(y,DL[y]);
			}
			else {
				int xt=0,xd=0;
				for(j=20;j>=0;j--) {
					if(xt+(1<<j)<W&&ST.getval(xt+(1<<j),W)>=Y[i]) xt+=1<<j;
					if(xd+(1<<j)<W&&SD.getval(xd+(1<<j),W)<=Y[i]) xd+=1<<j;
				}
				DR[y]-=L[i];
				if(max({Xs[xt],Xs[xd],DL[y]})>=DR[y]) {
					DR[y]=OW+1;
					if(Xs[xt]>Xs[xd]&&Xs[xt]>DL[y]) ST.update(xt,DT[xt]=0);
					if(Xs[xd]>Xs[xt]&&Xs[xd]>DL[y]) SD.update(xd,DD[xd]=OH+1);
					if(DL[y]>Xs[xt]&&DL[y]<Xs[xd]) SL.update(y,DL[y]=0);
				}
				SR.update(y,DR[y]);
			}
		}
		else {
			x=lower_bound(ALL(Xs),X[i])-Xs.begin();

			if(Y[i]==0) {
				int yl=H-1,yr=H-1;
				
				
				for(j=20;j>=0;j--) {
					if(SL.getval(0,yl-(1<<j)+1)>=X[i]) yl-=1<<j;
					if(SR.getval(0,yr-(1<<j)+1)<=X[i]) yr-=1<<j;
				}
				DT[x]+=L[i];
				if(min({Ys[yl],Ys[yr],DD[x]})<=DT[x]) {
				
					DT[x]=0;
					if(Ys[yl]<Ys[yr]&&Ys[yl]<DD[x]) SL.update(yl,DL[yl]=0);
					if(Ys[yr]<Ys[yl]&&Ys[yr]<DD[x]) SR.update(yr,DR[yr]=OW+1);
					if(DD[x]<Ys[yl]&&DD[x]<Ys[yr]) SD.update(x,DD[x]=OH+1);
				}
				ST.update(x,DT[x]);
			}
			else {
				int yl=0,yr=0;
				
				for(j=20;j>=0;j--) {
					if(yl+(1<<j)<H&&SL.getval(yl+(1<<j),H)>=X[i]) yl+=1<<j;
					if(yr+(1<<j)<H&&SR.getval(yr+(1<<j),H)<=X[i]) yr+=1<<j;
				}
				DD[x]-=L[i];
				if(max({Ys[yl],Ys[yr],DT[x]})>=DD[x]) {
					DD[x]=OH+1;
					if(Ys[yl]>Ys[yr]&&Ys[yl]>DT[x]) SL.update(yl,DL[yl]=0);
					if(Ys[yr]>Ys[yl]&&Ys[yr]>DT[x]) SR.update(yr,DR[yr]=OW+1);
					if(DT[x]>Ys[yl]&&DT[x]>Ys[yr]) ST.update(x,DT[x]=0);
				}
				SD.update(x,DD[x]);
			}
		}
		/*
		for(x=1;x<=W-2;x++) cout<<"#"<<Xs[x]<<" "<<DT[x]<<" "<<DD[x]<<endl;
		for(x=1;x<=H-2;x++) cout<<"!"<<Ys[x]<<" "<<DL[x]<<" "<<DR[x]<<endl;
		cout<<"!-------"<<endl;
		*/
	}
	ll ret=0;
	for(i=1;i<=W-2;i++) {
		//cout<<"#"<<Xs[i]<<" "<<DT[i]<<" "<<DD[i]<<endl;
		ret+=DT[i]+OH+1-DD[i];
	}
	for(i=1;i<=H-2;i++) {
		//cout<<"!"<<Ys[i]<<" "<<DL[i]<<" "<<DR[i]<<endl;
		ret+=DL[i]+OW+1-DR[i];
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0