結果

問題 No.1675 Strange Minimum Query
ユーザー chocoruskchocorusk
提出日時 2021-09-10 21:52:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,623 bytes
コンパイル時間 3,860 ms
コンパイル使用メモリ 197,772 KB
実行使用メモリ 16,444 KB
最終ジャッジ日時 2023-09-02 16:59:40
合計ジャッジ時間 15,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 50 ms
9,984 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 178 ms
14,792 KB
testcase_11 AC 75 ms
13,204 KB
testcase_12 AC 199 ms
15,996 KB
testcase_13 AC 257 ms
16,304 KB
testcase_14 AC 291 ms
16,436 KB
testcase_15 AC 268 ms
16,444 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 51 ms
6,352 KB
testcase_18 AC 67 ms
6,752 KB
testcase_19 AC 128 ms
13,536 KB
testcase_20 AC 191 ms
12,344 KB
testcase_21 AC 193 ms
14,500 KB
testcase_22 AC 233 ms
15,172 KB
testcase_23 RE -
testcase_24 AC 165 ms
11,152 KB
testcase_25 RE -
testcase_26 AC 71 ms
8,192 KB
testcase_27 AC 189 ms
15,024 KB
testcase_28 AC 108 ms
11,292 KB
testcase_29 AC 104 ms
12,876 KB
testcase_30 AC 73 ms
8,452 KB
testcase_31 RE -
testcase_32 AC 295 ms
16,356 KB
testcase_33 AC 290 ms
16,304 KB
testcase_34 AC 291 ms
16,268 KB
testcase_35 AC 309 ms
16,252 KB
testcase_36 AC 308 ms
16,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){
		a+=sz, b+=sz;
		Monoid ret=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) ret=f(ret, seg[--b]);
			if(a&1) ret=f(ret, seg[a++]);
		}
		return ret;
	}

	/*Monoid query(int a, int b){ //演算が非可換のとき
		a+=sz, b+=sz;
		Monoid retl=e, retr=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) retr=f(seg[--b], retr);
			if(a&1) retl=f(retl, seg[a++]);
		}
		return f(retl, retr);
	}*/

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
int n, q;
set<int> st;
int l[200020], r[200020], b[200020];
int main()
{
    cin>>n>>q;
    for(int i=0; i<n; i++){
        st.insert(i);
    }
    vector<int> ind(n);
    for(int i=0; i<q; i++){
        cin>>l[i]>>r[i]>>b[i];
        l[i]--;
        ind[i]=i;
    }
    sort(ind.begin(), ind.end(), [&](int i, int j){ return b[i]>b[j];});
    vector<int> ans(n, 1);
    for(auto i:ind){
        auto itr=st.lower_bound(l[i]);
        while(itr!=st.end() && *itr<r[i]){
            ans[*itr]=b[i];
            itr=st.erase(itr);
        }
    }
    const int INF=1e9+7;
    SegmentTree<int> seg(n, [&](int i, int j){ return min(i, j);}, INF, ans);
    bool dame=0;
    for(auto i:ind){
        if(seg.query(l[i], r[i])!=b[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i=0; i<n; i++){
        cout<<ans[i];
        if(i<n-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}
0