結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー hashiryohashiryo
提出日時 2019-06-02 12:57:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,042 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 211,584 KB
実行使用メモリ 216,944 KB
最終ジャッジ日時 2023-10-17 22:59:32
合計ジャッジ時間 38,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,629 ms
216,920 KB
testcase_01 AC 3,638 ms
216,920 KB
testcase_02 AC 3,348 ms
216,920 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3,389 ms
216,920 KB
testcase_06 AC 3,399 ms
216,920 KB
testcase_07 AC 3,426 ms
216,920 KB
testcase_08 AC 3,430 ms
216,920 KB
testcase_09 AC 3,424 ms
216,920 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 ll MOD = 1e18+9;


template <typename T,typename E>
class LazySegmentTree{
private:
    typedef function<T(T,T)> F;
    typedef function<T(T,E)> G;
    typedef function<E(E,E)> H;
    typedef function<E(E,int)> P;
    int n;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    P p;
    vector<T> dat;
    vector<E> laz;
    inline void eval(int len,int k){
        if(laz[k]==ei) return;
        if(k*2+1<n*2-1){
            laz[k*2+1]=h(laz[k*2+1],laz[k]);
            laz[k*2+2]=h(laz[k*2+2],laz[k]);
        }
        dat[k]=g(dat[k],p(laz[k],len));
        laz[k]=ei;
    }
public:
    LazySegmentTree(F f,G g,H h,T ti,E ei,P p=[](E a,int b){return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){}
    void init(int n_){
        n=1;
        while(n<n_) n<<=1;
        dat.assign(2*n-1,ti);
        laz.assign(2*n-1,ei);
    }
    void build(vector<T> v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--)
            dat[i]=f(dat[i*2+1],dat[i*2+2]);
    }
    T update(int a,int b,E x,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        eval(r-l,k);
        if(r<=a||b<=l) return dat[k];
        if(a<=l&&r<=b){
            laz[k]=h(laz[k],x);
            return g(dat[k],p(laz[k],r-l));
        }
        return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
                        update(a,b,x,k*2+2,(l+r)/2,r));
    }
    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        eval(r-l,k);
        if(r<=a||b<=l) return ti;
        if(a<=l&&r<=b) return dat[k];
        T vl=query(a,b,k*2+1,l,(l+r)/2);
        T vr=query(a,b,k*2+2,(l+r)/2,r);
        return f(vl,vr);
    }
    T operator[](const int &k) {return query(k,k+1);}
};

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