結果

問題 No.230 Splarraay スプラレェーイ
ユーザー sugarrrsugarrr
提出日時 2020-03-25 21:30:16
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 700 ms / 5,000 ms
コード長 6,989 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 165,140 KB
実行使用メモリ 31,872 KB
最終ジャッジ日時 2024-11-30 17:11:51
合計ジャッジ時間 6,336 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 4 ms
5,248 KB
testcase_06 AC 20 ms
5,248 KB
testcase_07 AC 4 ms
5,248 KB
testcase_08 AC 5 ms
5,248 KB
testcase_09 AC 261 ms
17,536 KB
testcase_10 AC 127 ms
5,248 KB
testcase_11 AC 140 ms
10,240 KB
testcase_12 AC 262 ms
17,536 KB
testcase_13 AC 31 ms
5,248 KB
testcase_14 AC 151 ms
31,872 KB
testcase_15 AC 356 ms
31,744 KB
testcase_16 AC 472 ms
31,744 KB
testcase_17 AC 700 ms
31,744 KB
testcase_18 AC 293 ms
31,872 KB
testcase_19 AC 441 ms
31,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////


//from betrue12 Codeforces 1326E
template<typename F, typename T, typename Func_mf, typename Func_op, typename Func_mv>
struct LazySegtree {
    ll n, n_org;
    vector<T> dat;
    vector<F> laz;
    Func_mf merge_functions; //lazyとlazyの演算
    Func_op operate;       //dataとlazyの演算
    Func_mv merge_values;  //dataとdataの演算
    F fe; //lazyの単位元かつ初期値
    T te; //dataの単位元かつ初期値
 
    LazySegtree(){}
    LazySegtree(ll n_org,
                Func_mf merge_functions,
                Func_op operate,
                Func_mv merge_values,
                F fe, T te):
                n_org(n_org),
                merge_functions(merge_functions),
                operate(operate),
                merge_values(merge_values),
                fe(fe), te(te){
        n = 1;
        while(n < n_org) n <<= 1;
        dat.resize(2*n-1, te);
        laz.resize(2*n-1, fe);
    }
 
    void build(vector<T>& A){
        for(ll k=0; k<ll(A.size()); k++) dat[k+n-1] = A[k];
        for(ll k=n-2; k>=0; k--) dat[k] = merge_values(dat[2*k+1], dat[2*k+2]);
    }
    void update(ll a, ll b, F x){ //[a,b]をupdate
        update(a, b+1, x, 0, 0, n);
    }
    T get(ll a, ll b){ //[a,b]から(最小値とか和とかを)get
        return query(a, b+1, 0, 0, n);
    }
 
    
private:
    void eval(ll k, ll w){
        if(laz[k] == fe) return;
        operate(dat[k], laz[k], w);
        if(k < n-1){
            merge_functions(laz[2*k+1], laz[k]);
            merge_functions(laz[2*k+2], laz[k]);
        }
        laz[k] = fe;
    }
    T query(ll a, ll b, ll k, ll lb, ll rb){
        eval(k, rb-lb);
        if(rb<=a || b<=lb) return te;
        if(a<=lb && rb<=b) return dat[k];
        ll mb = (lb+rb)>>1;
        T vl = query(a, b, 2*k+1, lb, mb);
        T vr = query(a, b, 2*k+2, mb, rb);
        return merge_values(vl, vr);
    }
    void update(ll a, ll b, F x, ll k, ll lb, ll rb){
        eval(k, rb-lb);
        if(b <= lb || rb <= a) return;
        if(a <= lb && rb <= b){
            merge_functions(laz[k], x);
            eval(k, rb-lb);
        }else{
            ll mb = (lb+rb)>>1;
            update(a, b, x, 2*k+1, lb, mb);
            update(a, b, x, 2*k+2, mb, rb);
            dat[k] = merge_values(dat[2*k+1], dat[2*k+2]);
        }
    }
};

const vector<ll>initial(2);

auto make_segtree = [](ll N){ //auto make_segtree = [&](ll N)
    
    using F = vector<ll>;
    using T = vector<ll>;
    auto merge_functions = [](F& f, F& g){
        rep(i,0,1)f[i]=g[i];
    };
    auto operate = [](T& v, F& f, ll w){
        rep(i,0,1)v[i]=f[i]*w;
    };
    auto merge_values = [](T& a, T& b){
        vector<ll>res(2);
        rep(i,0,1)res[i]=a[i]+b[i];
        return res;
    };
    F fe = initial;
    T te = initial;
    
    //区間加算と区間最小
    /*
    using F = ll;
    using T = ll;
    auto merge_functions = [](F& f, F& g){f += g;};
    auto operate = [](T& v, F& f, ll w){v += f;};
    auto merge_values = [](T& a, T& b){return min(a, b);};
    F fe = 0;
    T te = inf;*/
    
    //区間加算と区間最大
    /*
    using F = ll;
    using T = ll;
    auto merge_functions = [](F& f, F& g){f += g;};
    auto operate = [](T& v, F& f, ll w){v += f;};
    auto merge_values = [](T& a, T& b){return max(a, b);};
    F fe = 0;
    T te = -inf;*/
    
    //区間加算と区間和
    /*
    using F = ll;
    using T = ll;
    auto merge_functions = [](F& f, F& g){f += g;};
    auto operate = [](T& v, F& f, ll w){v += f*w;};
    auto merge_values = [](T& a, T& b){return a+b;};
    F fe = 0;
    T te = 0;*/
    
    //区間更新と区間最小
    /*
    using F=ll;
    using T=ll;
    auto merge_functions=[](F& f,F& g){f=g;};
    auto operate = [](T& v, F& f, ll w){v=f;};
    auto merge_values = [](T& a, T& b){return min(a, b);};
    F fe = inf;
    T te = inf;*/
    
    //区間更新と区間最大
    /*
    using F=ll;
    using T=ll;
    auto merge_functions=[](F& f,F& g){f=g;};
    auto operate = [](T& v, F& f, ll w){v=f;};
    auto merge_values = [](T& a, T& b){return max(a, b);};
    F fe = -inf;
    T te = -inf;*/
    
    //区間更新と区間和
    /*
    using F=ll;
    using T=ll;
    auto merge_functions=[](F& f,F& g){f=g;};
    auto operate = [](T& v, F& f, ll w){v=f*w;};
    auto merge_values = [](T& a, T& b){return a+b;};
    F fe = -inf;
    T te = 0;
    */
    return LazySegtree<F, T, decltype(merge_functions), decltype(operate), decltype(merge_values)>
        (N, merge_functions, operate, merge_values, fe, te);
};
/*
auto st = make_segtree(n);
vector<ll> init(n);
st.build(init);
 */

int main(){fastio
    ll n,q;cin>>n>>q;
    ll A,B;A=B=0;
    auto u=make_segtree(n);
    /*
    rep(i,0,n-1){
        auto y=u.get(i,i);
        for(auto x:y)cout<<x<<" ";cout<<endl;
    }*/
    while(1){
        q--;
        if(q<0){
            vector<ll>res=u.get(0,n-1);
            A+=res[0];
            B+=res[1];
            break;
        }
        ll a,b,c;cin>>a>>b>>c;
        if(a==0){
            vector<ll>res=u.get(b,c);
            if(res[0]>res[1])A+=res[0];
            else if(res[0]<res[1])B+=res[1];
        }else if(a==1){
            vector<ll>res;res.pb(1);res.pb(0);
            u.update(b,c,res);
        }else{
            vector<ll>res;res.pb(0);res.pb(1);
            u.update(b,c,res);
        }
        /*
        rep(i,0,n-1){
            vector<ll>res=u.get(i,i);
            for(auto x:res)cout<<x<<" ";cout<<endl;
        }cout<<"---------"<<endl;*/
    }
    
    cout<<A<<" "<<B<<endl;
    return 0;
}
0