結果

問題 No.1675 Strange Minimum Query
ユーザー 👑 potato167potato167
提出日時 2021-09-10 21:31:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 3,024 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 207,820 KB
実行使用メモリ 20,836 KB
最終ジャッジ日時 2023-09-02 16:05:07
合計ジャッジ時間 11,004 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 105 ms
10,508 KB
testcase_04 AC 140 ms
12,456 KB
testcase_05 AC 17 ms
7,744 KB
testcase_06 AC 127 ms
11,648 KB
testcase_07 AC 141 ms
13,852 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 66 ms
11,620 KB
testcase_11 AC 22 ms
8,448 KB
testcase_12 AC 77 ms
12,792 KB
testcase_13 AC 92 ms
15,252 KB
testcase_14 AC 119 ms
20,836 KB
testcase_15 AC 125 ms
20,728 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 29 ms
6,556 KB
testcase_18 AC 41 ms
7,288 KB
testcase_19 AC 63 ms
12,060 KB
testcase_20 AC 129 ms
15,020 KB
testcase_21 AC 122 ms
15,428 KB
testcase_22 AC 158 ms
17,364 KB
testcase_23 AC 115 ms
10,704 KB
testcase_24 AC 114 ms
12,416 KB
testcase_25 AC 74 ms
8,636 KB
testcase_26 AC 40 ms
8,348 KB
testcase_27 AC 111 ms
14,608 KB
testcase_28 AC 58 ms
11,116 KB
testcase_29 AC 43 ms
10,760 KB
testcase_30 AC 41 ms
8,232 KB
testcase_31 AC 144 ms
12,804 KB
testcase_32 AC 214 ms
19,052 KB
testcase_33 AC 215 ms
19,216 KB
testcase_34 AC 218 ms
19,104 KB
testcase_35 AC 217 ms
17,916 KB
testcase_36 AC 219 ms
17,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
ll mod=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}

namespace po167{
template <class T,T (*op)(T,T),T(*e)()>
struct segment_tree{
	int _n,size;
	std::vector<T> seg;
	int ceil_pow2(int a){
		int b=1;
		while(a>b){
			b<<=1;
		}
		return b;
	}
	void update(int k){seg[k]=op(seg[k*2],seg[k*2+1]);};
	segment_tree(int n) :_n(n){
		size=ceil_pow2(n);
		seg=std::vector<T>(size*2,e());
	}
	segment_tree(std::vector<T> &p) :_n((int) p.size()){
		size=ceil_pow2(_n);
		seg=std::vector<T>(size*2,e());
		for(int i=0;i<_n;i++) seg[i+size]=p[i];
		for(int i=size-1;i>0;i--) update(i);
	}
	void set(int ind,T val){
		assert(0<=ind&&ind<_n);
		ind+=size;
		seg[ind]=val;
		while(ind!=1){
			ind>>=1;
			update(ind);
		}
	}
	T get(int ind){
		assert(0<=ind&&ind<_n);
		return seg[ind+size];
	}
	T query(int l,int r){
		assert(0<=l&&l<_n);
		assert(0<=r&&r<=_n);
		T l_val=e();
		T r_val=e();
		l+=size,r+=size;
		while(l<r){
			if(l&1) l_val=op(l_val,seg[l]),l+=1;
			if(r&1) r-=1,r_val=op(seg[r],r_val);
			r>>=1;
			l>>=1;
		}
		return op(l_val,r_val);
	}
};
}
using po167::segment_tree;

using F= int;
F MIN(F a,F b){return min(a,b);}
F e(){return 1e9;}

namespace po167{
template<class T>
struct my_set{
	priority_queue<T> exist;
	priority_queue<T> absent;
	void op(){
		while(!absent.empty()&&exist.top()==absent.top()){
			exist.pop();
			absent.pop();
		}
	}
	T get(){
		op();
		return exist.top();
	}
	void insert(T a){
		exist.push(a);
	}
	void delate(T a){
		absent.push(a);
	}
};
}
using po167::my_set;

//  rainy ~ 雨に打たれて ~
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N,Q;
	cin>>N>>Q;
	segment_tree<F,MIN,e> seg(N);
	vector<vector<int>> G(N+1);
	my_set<int> s;
	s.insert(1);
	vector<int> L(Q),R(Q),B(Q);
	rep(i,Q){
		int l,r,b;
		cin>>l>>r>>b;
		L[i]=l,R[i]=r,B[i]=b;
		G[l-1].push_back(b);
		G[r].push_back(-b);
	}
	rep(i,N){
		for(auto x:G[i]){
			if(x<0) s.delate(-x);
			else s.insert(x);
		}
		seg.set(i,s.get());
	}
	int J=1;
	rep(i,Q){
		if(seg.query(L[i]-1,R[i])!=B[i]) J=0;
	}
	if(J){
		rep(i,N){
			if(i!=0) cout<<" ";
			cout<<seg.get(i);
		}
		cout<<"\n";
	}
	else cout<<"-1\n";
}

0