結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー 👑 kmjpkmjp
提出日時 2015-07-25 00:50:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,821 ms / 10,000 ms
コード長 3,303 bytes
コンパイル時間 2,009 ms
コンパイル使用メモリ 168,256 KB
実行使用メモリ 185,236 KB
最終ジャッジ日時 2023-08-02 21:10:49
合計ジャッジ時間 16,638 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,723 ms
183,724 KB
testcase_01 AC 1,821 ms
183,940 KB
testcase_02 AC 1,230 ms
183,844 KB
testcase_03 AC 1,201 ms
183,832 KB
testcase_04 AC 65 ms
181,200 KB
testcase_05 AC 1,209 ms
184,564 KB
testcase_06 AC 1,214 ms
185,236 KB
testcase_07 AC 1,204 ms
184,152 KB
testcase_08 AC 1,250 ms
183,744 KB
testcase_09 AC 1,213 ms
184,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef __int128 lll;
#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 X[161010];
ll L[161010],R[161010];

template<int NV> class SegTree_Lazy {
public:
	vector<lll> val,tot;
	vector<char> clean;
	SegTree_Lazy(){val.resize(NV*2); tot.resize(NV*2);clean.resize(NV*2);};
	lll 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[y]-V[x]) + 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 {
			if(clean[2*k]) {
				clean[2*k]=val[2*k]=tot[2*k]=0;
				if(2*k<=NV) {
					clean[2*k*2]=clean[2*k*2+1]=1;
					val[2*k*2]=val[2*k*2+1]=tot[2*k*2]=tot[2*k*2+1]=0;
				}
			}
			if(clean[2*k+1]) {
				clean[2*k+1]=val[2*k+1]=tot[2*k+1]=0;
				if(2*k+1<=NV) {
					clean[(2*k+1)*2]=clean[(2*k+1)*2+1]=1;
					val[(2*k+1)*2]=val[(2*k+1)*2+1]=tot[(2*k+1)*2]=tot[(2*k+1)*2+1]=0;
				}
			}
			val[2*k]+=val[k];
			tot[2*k]+=val[k]*(V[(l+r)/2]-V[l]);
			val[2*k+1]+=val[k];
			tot[2*k+1]+=val[k]*(V[r]-V[(l+r)/2]);
			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]=clean[2*k+1]=1;
				val[2*k]=val[2*k+1]=tot[2*k]=tot[2*k+1]=0;
			}
			clean[k]=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[r]-V[l])+tot[2*k]+tot[2*k+1];
		}
	}
};
SegTree_Lazy<1<<19> 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+3);
	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());
	while(V.size()<(1<<19)+5) V.push_back(V.back());
	lll 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) {
			lll 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);
			}
		}
	}
	lll mo=1000000000;
	mo*=1000000000;
	mo+=9;
	FOR(i,5) {
		bonus[i] += st[i].getval(0,V.size());
		cout<<(ll)(bonus[i]%mo);
		cout<<" \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