結果

問題 No.1675 Strange Minimum Query
ユーザー mugen_1337mugen_1337
提出日時 2021-09-10 22:51:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,077 bytes
コンパイル時間 3,386 ms
コンパイル使用メモリ 221,760 KB
実行使用メモリ 21,336 KB
最終ジャッジ日時 2023-09-02 20:13:12
合計ジャッジ時間 18,560 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,368 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 286 ms
21,004 KB
testcase_14 AC 407 ms
21,276 KB
testcase_15 AC 320 ms
20,824 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 88 ms
6,780 KB
testcase_18 AC 121 ms
7,168 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 471 ms
19,928 KB
testcase_23 AC 315 ms
10,992 KB
testcase_24 AC 312 ms
11,312 KB
testcase_25 AC 206 ms
8,320 KB
testcase_26 WA -
testcase_27 AC 326 ms
17,552 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 410 ms
13,792 KB
testcase_32 AC 594 ms
20,016 KB
testcase_33 AC 599 ms
20,476 KB
testcase_34 AC 588 ms
19,820 KB
testcase_35 AC 461 ms
21,336 KB
testcase_36 AC 461 ms
19,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
    using F=function<Monoid(Monoid,Monoid)>;
    using G=function<Monoid(Monoid,OperatorMonoid)>;
    using H=function<OperatorMonoid(OperatorMonoid,OperatorMonoid)>;
 
    private:
 
    int sz,height;
    vector<Monoid> data;
    vector<OperatorMonoid> lazy;
    // propagate lazy value -> data (node k)
    inline void propagate(int k){
        if(lazy[k]!=OM0){
            if(k<sz){
                lazy[2*k+0]=h(lazy[2*k+0],lazy[k]);
                lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
            }
            data[k]=g(data[k],lazy[k]);
            lazy[k]=OM0;
        }
    }
 
    void update(int a,int b,const OperatorMonoid &x,int k,int l,int r){
        propagate(k);
        if(b<=l or r<=a) return ;
        if(a<=l and r<=b){
            lazy[k]=h(lazy[k],x);
            propagate(k);
        }else{
            update(a,b,x,2*k,l,(l+r)/2);
            update(a,b,x,2*k+1,(l+r)/2,r);
            data[k]=f(data[2*k],data[2*k+1]);
        }
    }
 
    Monoid query(int a,int b,int k,int l,int r){
        if(b<=l or r<=a) return M1;
 
        propagate(k);
        if(a<=l and r<=b) return data[k];
 
        Monoid L=query(a,b,2*k+0,l,(l+r)/2);
        Monoid R=query(a,b,2*k+1,(l+r)/2,r);
        return f(L,R);
    }
 
    public:
 
    const F f;
    const G g;
    const H h;
    const Monoid M1;
    const OperatorMonoid OM0;
 
    LazySegmentTree(int n,const F f,const G g,const H h,const Monoid &M1,const OperatorMonoid OM0)
    : f(f),g(g),h(h),M1(M1),OM0(OM0) {
        sz=1;height=0;
        while(sz<n) sz<<=1,height++;
        data.assign(2*sz,M1);lazy.assign(2*sz,OM0);
    }
 
    void set(int k,const Monoid &x){
        data[k+sz]=x;
    }
    void build(){
        for(int k=sz-1;k>0;k--) data[k]=f(data[2*k+0],data[2*k+1]);
    }
    void update(int a,int b,const OperatorMonoid &x){
        update(a,b,x,1,0,sz);
    }
    Monoid query(int a,int b){
        return query(a,b,1,0,sz);
    }
    Monoid operator[](const int &k){
        return query(k,k+1);
    }
}; 

// // range set range min
// using M=ll;
// using OM=ll;
// const M M1=LINF;
// const OM OM0=-LINF;
// M segf(M a,M b){
//     return (a<b?a:b);
// }
// M segg(M a,OM b){
//     return (b==OM0?a:b);
// }
// OM segh(OM a,OM b){
//     return (b==OM0?a:b);
// }
 
// // range set range max
// using M=ll;
// using OM=ll;
// const M M1=-LINF;
// const OM OM0=-LINF;
// M segf(M a,M b){
//     return (a>b?a:b);
// }
// M segg(M a,OM b){
//     return (b==OM0?a:b);
// }
// OM segh(OM a,OM b){
//     return (b==OM0?a:b);
// }
 
// // range add range min
// using M=ll;
// using OM=ll;
// const M M1=LINF;
// const OM OM0=0;
// M segf(M a,M b){
//     return (a<b?a:b);
// }
// M segg(M a,OM b){
//     return a+b;
// }
// OM segh(OM a,OM b){
//     return a+b;
// }
 
// // range add range max
// using M=ll;
// using OM=ll;
// const M M1=-LINF;
// const OM OM0=0;
// M segf(M a,M b){
//     return (a>b?a:b);
// }
// M segg(M a,OM b){
//     return a+b;
// }
// OM segh(OM a,OM b){
//     return a+b;
// }
 
// range set range sum (sum, count)
using M=pair<ll,ll>;
using OM=ll;
const M M1=M(0,0);
const OM OM0=-LINF;
M segf(M a,M b){
    return M(a.first+b.first,a.second+b.second);
}
M segg(M a,OM b){
    return M(a.second*b,a.second);
}
OM segh(OM a,OM b){
    return (b==OM0?a:b);
}

// // range add range sum (sum, count)
// using M=pair<ll,ll>;
// using OM=ll;
// const M M1=M(0,0);
// const OM OM0=0;
// M segf(M a,M b){
//     return M(a.first+b.first,a.second+b.second);
// }
// M segg(M a,OM b){
//     return M(a.first+a.second*b,a.second);
// }
// OM segh(OM a,OM b){
//     return a+b;
// }

signed main(){
    int N,Q;cin>>N>>Q;
    LazySegmentTree<M,OM> seg(N,segf,segg,segh,M1,OM0);
    rep(i,N) seg.set(i,{0,1});
    seg.build();

    using T=tuple<ll,int,int>;
    vector<T> V;
    rep(i,Q){
        int l,r;ll B;cin>>l>>r>>B;l--;
        V.emplace_back(B,l,r);
    }

    sort(ALL(V));
    for(auto [B,l,r]:V){
        seg.update(l,r,B);
    }

    rep(i,N) cout<<seg[i].first<<(i+1==N?"\n":" ");
    return 0;
}
0