結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー 沙耶花沙耶花
提出日時 2022-03-23 17:28:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 853 ms / 10,000 ms
コード長 2,453 bytes
コンパイル時間 4,312 ms
コンパイル使用メモリ 268,952 KB
実行使用メモリ 148,912 KB
最終ジャッジ日時 2024-04-20 01:42:44
合計ジャッジ時間 13,753 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 848 ms
148,100 KB
testcase_01 AC 832 ms
148,152 KB
testcase_02 AC 815 ms
148,912 KB
testcase_03 AC 759 ms
148,080 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 853 ms
148,292 KB
testcase_06 AC 800 ms
147,992 KB
testcase_07 AC 814 ms
148,528 KB
testcase_08 AC 837 ms
148,188 KB
testcase_09 AC 813 ms
148,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

struct Data{
	long long cnt[6],sum[6];
	Data(){
		rep(i,6){
			cnt[i] = 0;
			sum[i] = 0;
		}
	}
};

struct D2{
	int color=-1;
	long long num = 0;
	bool f = false;
};

Data op(Data a,Data b){
	rep(i,6){
		a.cnt[i] += b.cnt[i];
		a.sum[i] += b.sum[i];
	}
	return a;
}
Data e(){
	return Data();
}

Data mapping(D2 a,Data b){
	if(a.color==-1)return b;
	if(a.f){
		rep(i,6){
			if(i==a.color)continue;
			b.cnt[a.color] += b.cnt[i];
			b.sum[i] = 0;
			b.cnt[i] = 0;
		}
		b.sum[a.color] = b.cnt[a.color] * a.num;
		
	}
	else{
		//cout<<a.color<<','<<a.num<<endl;
		rep(i,6){
			if(i!=a.color){
				b.cnt[a.color] += b.cnt[i];
				b.cnt[i] = 0;
				b.sum[i] = 0;
			}
		}
		b.sum[a.color] += b.cnt[a.color] * a.num;
	}
	return b;
}
	
D2 composition(D2 a,D2 b){
	
	if(a.color==-1)return b;
	if(b.color==-1)return a;
	if(a.f)return a;
	if(a.color==b.color){
		a.num += b.num;
		a.f |= b.f;
	}
	else{
		a.f = true;
	}
	return a;
	
}

D2 id(){
	return D2();
}

int main(){
	long long n,q;
	cin>>n>>q;
	
	
	vector<long long> x(q),l(q),r(q);
	vector<long long> t;
	t.push_back(0);
	t.push_back(n);
	rep(i,q){
		cin>>x[i]>>l[i]>>r[i];
		r[i]++;
		t.push_back(l[i]);
		t.push_back(r[i]);
	}
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	rep(i,q){
		l[i] = distance(t.begin(),lower_bound(t.begin(),t.end(),l[i]));
		r[i] = distance(t.begin(),lower_bound(t.begin(),t.end(),r[i]));
	}
	lazy_segtree<Data,op,e,D2,mapping,composition,id> seg;
	{
		vector<Data> temp(t.size()-1);
		rep(i,temp.size()){
			Data x;
			x.cnt[0] = t[i+1] - t[i];
			temp[i] = x;
		}
		seg = lazy_segtree<Data,op,e,D2,mapping,composition,id>(temp);
	}
		
	vector<__int128> ans(6,0);
	rep(i,q){
		if(x[i]!=0){
			D2 tt;
			tt.color = x[i];
			tt.num = 1;
			seg.apply(l[i],r[i],tt);
		}
		else{
			auto ret = seg.prod(l[i],r[i]);
			long long m = -1;
			for(int j=1;j<6;j++){
				m = max(m,ret.sum[j]);
			}
			int c = 0;
			for(int j=1;j<6;j++){
				if(m==ret.sum[j])c++;
			}
			if(c==1){
				for(int j=1;j<6;j++){
					if(m==ret.sum[j]){
						ans[j] += m;
					}
				}
			}
		}
	}
	long long MM = 1000000000000000009;
	auto ret = seg.all_prod();
	
	rep(j,6)ans[j] += ret.sum[j];
	for(int i=1;i<6;i++){
		if(i!=1)cout<<' ';
		cout<<((long long)(ans[i]%MM));
	}
	cout<<endl;
	
	return 0;
}
0