結果

問題 No.1675 Strange Minimum Query
ユーザー mugen_1337mugen_1337
提出日時 2021-09-10 22:57:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,211 bytes
コンパイル時間 2,612 ms
コンパイル使用メモリ 220,172 KB
実行使用メモリ 17,620 KB
最終ジャッジ日時 2023-09-02 20:36:36
合計ジャッジ時間 11,107 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 249 ms
9,376 KB
testcase_04 AC 244 ms
11,516 KB
testcase_05 AC 23 ms
7,552 KB
testcase_06 AC 297 ms
9,448 KB
testcase_07 AC 342 ms
12,748 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 202 ms
16,336 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,372 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
    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));
    reverse(ALL(V));
    for(auto [B,l,r]:V){
        seg.update(l,r,B);
    }

    for(auto [B,l,r]:V){
        if(seg.query(l,r)!=B){
            cout<<-1<<endl;
            return 0;
        }
    }

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