結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー 👑 kmjpkmjp
提出日時 2015-07-24 23:50:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,722 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 163,020 KB
実行使用メモリ 73,632 KB
最終ジャッジ日時 2023-09-23 00:00:31
合計ジャッジ時間 6,341 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 33 ms
64,484 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

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))
//-------------------------------------------------------


vector<ll> V;
ll N;
int Q;
int VL;
int X[161010];
ll L[161010],R[161010];

template<int NV> class SegTree_Lazy {
public:
	vector<ll> val,tot,clean;
	SegTree_Lazy(){val.resize(NV*2); tot.resize(NV*2);clean.resize(NV*2);};
	ll getval(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return 0;
		if(clean[k]) return 0;
		if(x<=l && r<=y) return tot[k];
		x=max(x,l);
		y=min(y,r);
		return val[k]*(V[min(y,VL)]-V[min(x,VL)]) + getval(x,y,l,(l+r)/2,k*2) + getval(x,y,(l+r)/2,r,k*2+1);
	}

	void clear(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return;
		if(clean[k]) return;
		if(x<=l && r<=y) {
			clean[k]=1;
			val[k]=tot[k]=0;
		}
		else {
			val[2*k]+=val[k];
			val[2*k+1]+=val[k];
			val[k]=0;
			clear(x,y,l,(l+r)/2,k*2);
			clear(x,y,(l+r)/2,r,k*2+1);
			tot[k]=tot[2*k]+tot[2*k+1];
		}
	}
	void inc(int x,int y,int l=0,int r=NV,int k=1) {
		if(r<=x || y<=l) return;
		if(clean[k]) {
			if(k<=NV) {
				clean[2*k]=1;
				clean[2*k+1]=1;
			}
			clean[k]=0;
			val[k]=tot[k]=0;
		}
		
		if(x<=l && r<=y) {
			val[k]++;
			tot[k]+=V[r]-V[l];
		}
		else {
			inc(x,y,l,(l+r)/2,k*2);
			inc(x,y,(l+r)/2,r,k*2+1);
			tot[k]=val[k]*(V[min(r,VL)]-V[min(l,VL)])+tot[2*k]+tot[2*k+1];
		}
	}
};
SegTree_Lazy<1<<18> st[5];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	V.push_back(0);
	V.push_back(N+2);
	FOR(i,Q) {
		cin>>X[i]>>L[i]>>R[i];
		L[i]++,R[i]++;
		V.push_back(L[i]);
		V.push_back(R[i]+1);
	}
	
	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());
	VL=V.size()-1;
	ll bonus[5]={};
	
	FOR(i,Q) {
		int LL=lower_bound(ALL(V),L[i])-V.begin();
		int RR=lower_bound(ALL(V),R[i]+1)-V.begin();
		if(X[i]==0) {
			ll bo[5]={};
			int be=0;
			FOR(j,5) {
				bo[j]=st[j].getval(LL,RR);
				if(bo[j]>bo[be]) be=j;
			}
			FOR(j,5) if(be>=0 && j!=be && bo[j]==bo[be]) be=-1;
			if(be!=-1) bonus[be]+=bo[be];
		}
		else {
			FOR(j,5) {
				if(X[i]==j+1) st[j].inc(LL,RR);
				else st[j].clear(LL,RR);
			}
		}
	}
	FOR(i,5) {
		bonus[i] += st[i].getval(0,V.size());
		_P("%lld",bonus[i]);
		_P("%c"," \n"[i==4]);
	}
	
	
}


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