結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー hashiryohashiryo
提出日時 2019-06-02 13:52:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,838 ms / 10,000 ms
コード長 4,349 bytes
コンパイル時間 2,442 ms
コンパイル使用メモリ 211,788 KB
実行使用メモリ 198,124 KB
最終ジャッジ日時 2023-10-17 23:00:14
合計ジャッジ時間 29,842 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,823 ms
198,124 KB
testcase_01 AC 2,838 ms
198,124 KB
testcase_02 AC 2,597 ms
198,124 KB
testcase_03 AC 2,190 ms
198,124 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2,594 ms
198,124 KB
testcase_06 AC 2,627 ms
198,124 KB
testcase_07 AC 2,623 ms
198,124 KB
testcase_08 AC 2,631 ms
198,124 KB
testcase_09 AC 2,633 ms
198,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 ull MOD = 1000000000000000009;


template <typename T,typename E>
class LazySegmentTree{
private:
    using F = function<T(T,T)>;
    using G = function<T(T,E)>;
    using H = function<E(E,E)>;
    int n,height;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    vector<T> dat;
    vector<E> laz;
    inline T reflect(int k){
        return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
    }
    inline void eval(int k){
        if(laz[k]==ei) return;
        laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
        laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
        dat[k]=reflect(k);
        laz[k]=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]=f(reflect((k<<1)|0),reflect((k<<1)|1));
    }
public:
    LazySegmentTree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}

    void init(int n_){
        n=1;height=0;
        while(n<n_) n<<=1,height++;
        dat.assign(2*n,ti);
        laz.assign(2*n,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]=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]=h(laz[l],x),l++;
            if(r&1) --r,laz[r]=h(laz[r],x);
        }
        recalc(a);
        recalc(b);
    }
    void set_val(int a,T x){
        thrust(a+=n);
        dat[a]=x;laz[a]=ei;
        recalc(a);
    }
    T query(int a,int b){
        thrust(a+=n);
        thrust(b+=n-1);
        T vl=ti,vr=ti;
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,reflect(l++));
            if(r&1) vr=f(reflect(--r),vr);
        }
        return f(vl,vr);
    }
    T operator[](const int k){return query(k,k+1);}
};

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<tuple<ull,ull> >A(v.size());
  for(ll i=0;i<(ll)v.size();i++){
    mp[v[i]]=i;
    A[i] = make_tuple(0,i+1<(ll)v.size()?v[i+1]-v[i]:1);
  }
  auto f=[](tuple<ull,ull> a,tuple<ull,ull> b){return make_tuple((get<0>(a)+get<0>(b))%MOD,get<1>(a)+get<1>(b));};
  auto g=[](tuple<ull,ull> a,tuple<ull,bool> b){return make_tuple((get<1>(b)? get<0>(b)*get<1>(a):get<0>(b)*get<1>(a)%MOD+get<0>(a))%MOD,get<1>(a));};
  auto h=[](tuple<ull,bool> a,tuple<ull,bool> b){return get<1>(b)? b:make_tuple(get<0>(a)+get<0>(b),get<1>(a));};
  vector<LazySegmentTree<tuple<ull,ull>,tuple<ull,bool> > > seg(5,LazySegmentTree<tuple<ull,ull>,tuple<ull,bool> >(f,g,h,make_tuple(0,0),make_tuple(0,false)));
  for(ll i=0;i<5;i++)seg[i].build(A);
  vector<ull> 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,make_tuple(1,false));
        }else{
          seg[i].update(l,r,make_tuple(0,true));
        }
      }
    }else{
      ull mx=0,mxi=0;
      bool one=false;
      for(ll i=0;i<5;i++){
        ull sum,dum;
        tie(sum,dum)=seg[i].query(l,r);
        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++){
    ull sum,dum;
    tie(sum,dum)=seg[i].query(0,mp[N]);
    //debug(score[i]);
    //debug(sum);
    score[i] = (score[i]+sum%MOD)%MOD;
    cout<<score[i]<<(i<4? " ":"\n");
  }
  return 0;
}
0