結果
| 問題 |
No.255 Splarrraaay スプラーレェーーイ
|
| コンテスト | |
| ユーザー |
hashiryo
|
| 提出日時 | 2019-06-04 14:45:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,103 ms / 10,000 ms |
| コード長 | 4,451 bytes |
| コンパイル時間 | 2,023 ms |
| コンパイル使用メモリ | 197,100 KB |
| 実行使用メモリ | 229,280 KB |
| 最終ジャッジ日時 | 2024-09-17 20:50:10 |
| 合計ジャッジ時間 | 22,304 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include<bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1000000000000000009;
template <typename M>
class LazySegmentTree{
private:
using T=typename M::T;
using E=typename M::E;
int n,height;
vector<T> dat;
vector<E> laz;
inline T reflect(int k){
return laz[k]==M::ei()?dat[k]:M::g(dat[k],laz[k]);
}
inline void eval(int k){
if(laz[k]==M::ei()) return;
laz[(k<<1)|0]=M::h(laz[(k<<1)|0],laz[k]);
laz[(k<<1)|1]=M::h(laz[(k<<1)|1],laz[k]);
dat[k]=reflect(k);
laz[k]=M::ei();
}
inline void thrust(int k){
for(int i=height;i;i--) eval(k>>i);
}
inline void recalc(int k){
while(k>>=1)
dat[k]=M::f(reflect((k<<1)|0),reflect((k<<1)|1));
}
public:
LazySegmentTree(){}
LazySegmentTree(int n_){init(n_);}
LazySegmentTree(const vector<T> &v){build(v);}
void init(int n_){
n=1;height=0;
while(n<n_) n<<=1,height++;
dat.assign(2*n,M::ti());
laz.assign(2*n,M::ei());
}
void build(const vector<T> &v){
int n_=v.size();
init(n_);
for(int i=0;i<n_;i++) dat[n+i]=v[i];
for(int i=n-1;i;i--)
dat[i]=M::f(dat[(i<<1)|0],dat[(i<<1)|1]);
}
void update(int a,int b,E x){
thrust(a+=n);
thrust(b+=n-1);
for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
if(l&1) laz[l]=M::h(laz[l],x),l++;
if(r&1) --r,laz[r]=M::h(laz[r],x);
}
recalc(a);
recalc(b);
}
void set_val(int a,T x){
thrust(a+=n);
dat[a]=x;laz[a]=M::ei();
recalc(a);
}
T query(int a,int b){
thrust(a+=n);
thrust(b+=n-1);
T vl=M::ti(),vr=M::ti();
for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
if(l&1) vl=M::f(vl,reflect(l++));
if(r&1) vr=M::f(reflect(--r),vr);
}
return M::f(vl,vr);
}
T operator[](const int k){return query(k,k+1);}
};
struct RuaqRsumq {
struct T{
ll val,size;
T(){}
T(ll v, ll s = 1) : val(v), size(s) {}
};
struct E{
ll val;
bool clear;
E(ll v,bool c=false):val(v),clear(c){}
bool operator==(const E& r){
return val==r.val&&clear==r.clear;
}
};
static T ti() { return T(0,0); }
static E ei() { return E(0); }
static T f(const T& l, const T& r) { return T((l.val+r.val)%MOD, (l.size+r.size)%MOD); }
static T g(const T& l, const E& r) { return T((!r.clear*l.val+l.size * r.val%MOD)%MOD, l.size); }
static E h(const E& l, const E& r) { return r.clear? r:E(l.val+r.val,l.clear); }
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
//debug(MOD);
ll N;cin>>N;
ll Q;cin>>Q;
vector<tuple<ll,ll,ll>> query(Q);
vll v;
v.push_back(0);
for(ll q=0;q<Q;q++){
ll x,l,r;cin>>x>>l>>r;
query[q]=make_tuple(x,l,r+1);
v.push_back(l);
v.push_back(r+1);
}
v.push_back(N);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
map<ll,ll> mp;
vector<RuaqRsumq::T >A(v.size());
for(ll i=0;i<(ll)v.size();i++){
mp[v[i]]=i;
A[i] = {0,i+1<(ll)v.size()?v[i+1]-v[i]:1};
}
vector<LazySegmentTree<RuaqRsumq> > seg(5,LazySegmentTree<RuaqRsumq>(A));
vector<ll> score(5,0);
for(ll q=0;q<Q;q++){
ll x,l,r;
tie(x,l,r)=query[q];
l=mp[l];
r=mp[r];
if(x){
x--;
for(ll i=0;i<5;i++){
if(x==i){
seg[i].update(l,r,{1,false});
}else{
seg[i].update(l,r,{0,true});
}
}
}else{
ll mx=0,mxi=0;
bool one=false;
for(ll i=0;i<5;i++){
ll sum=seg[i].query(l,r).val;
sum %= MOD;
if(mx==sum){
one=false;
}else if(mx<sum){
one=true;
mx=sum;
mxi=i;
}
}
if(one){
score[mxi]=(score[mxi]+mx%MOD)%MOD;
//cout<<mx<<endl;
}
}
}
for(ll i=0;i<5;i++){
ll sum=seg[i].query(0,mp[N]).val;
//debug(score[i]);
//debug(sum);
score[i] = (score[i]+sum%MOD)%MOD;
cout<<score[i]<<(i<4? " ":"\n");
}
return 0;
}
hashiryo