結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
36,148 KB
testcase_01 AC 13 ms
36,204 KB
testcase_02 AC 13 ms
35,988 KB
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 AC 13 ms
36,144 KB
testcase_17 AC 13 ms
38,104 KB
testcase_18 AC 13 ms
36,204 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 13 ms
36,064 KB
testcase_23 AC 13 ms
37,976 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 13 ms
36,132 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 12 ms
35,924 KB
testcase_62 WA -
testcase_63 AC 13 ms
36,144 KB
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 AC 14 ms
38,104 KB
testcase_68 AC 13 ms
36,104 KB
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 AC 313 ms
38,536 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]>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(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