結果

問題 No.255 Splarrraaay スプラーレェーーイ
ユーザー hashiryohashiryo
提出日時 2019-06-01 16:05:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 4,229 bytes
コンパイル時間 2,737 ms
コンパイル使用メモリ 198,912 KB
実行使用メモリ 168,588 KB
最終ジャッジ日時 2023-10-17 22:46:26
合計ジャッジ時間 30,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 1e9+7;


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);
  ll N,Q;cin>>N>>Q;
  vector<tuple<ll,ll,ll> > query(Q);
  vll a;
  for(ll q=0;q<Q;q++){
    ll x,l,r;cin>>x>>l>>r;
    query[q]=make_tuple(x,l,r);
    a.push_back(l);
    a.push_back(r);
    a.push_back(r+1);
  }
  a.push_back(0);
  a.push_back(N);
  sort(a.begin(),a.end());
  a.erase(unique(a.begin(),a.end()),a.end());
  //debugArray(a,a.size());
  map<ll,ll> mp;
  for(ll i=0;i<(ll)a.size();i++){
    mp[a[i]]=i;
  }
  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,ll b){
    return b>=0? make_tuple(get<0>(a)+get<1>(a)*b,get<1>(a)):make_tuple(0ll,get<1>(a));
  };
  auto h=[](ll a,ll b){return !b? a:b>0?max(a,0ll)+b:-1;};
  vector<LazySegmentTree<tuple<ll,ll>,ll> > seg(5,LazySegmentTree<tuple<ll,ll>,ll>(f,g,h,make_tuple(0,0),0));
  vector<tuple<ll,ll> > V(a.size());
  for(ll i=0;i<(ll)a.size();i++){
    V[i] = make_tuple(0,i+1<(ll)a.size()?a[i+1]-a[i]:1);
    //debug(get<1>(V[i]));
  }
  for(ll i=0;i<5;i++)seg[i].build(V);
  vll score(5,0);
  for(ll q=0;q<Q;q++){
    //debug(q);
    ll x,l,r;
    tie(x,l,r)=query[q];
    l = mp[l];
    r = mp[r];
    //debug(l);
    //debug(r);
    if(!x){
      bool one=false;
      ll mx=0,mxi=0;
      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]+=mx;
      }
      //debug(one);
    }else{
      x--;
      for(ll i=0;i<5;i++){
        seg[i].update(l,r+1,x==i?1:-1);
        seg[i].query(l,r+1);
      }
    }
    /*
    if(q==4){
      for(ll i=0;i<(ll)a.size();i++){
        debug(get<0>(seg[0][i]));
      }
    }
    */
  }
  for(ll i=0;i<5;i++){
    score[i] += get<0>(seg[i].query(0,a.size()));
    cout<<score[i]<<(i<4? " ":"\n");
  }
  return 0;
}
0