結果
| 問題 |
No.255 Splarrraaay スプラーレェーーイ
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-03-23 17:28:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 865 ms / 10,000 ms |
| コード長 | 2,453 bytes |
| コンパイル時間 | 4,258 ms |
| コンパイル使用メモリ | 265,668 KB |
| 最終ジャッジ日時 | 2025-01-28 11:08:28 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#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;
}
沙耶花