結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2021-09-10 21:31:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 209 ms / 2,000 ms |
| コード長 | 3,024 bytes |
| コンパイル時間 | 2,182 ms |
| コンパイル使用メモリ | 205,288 KB |
| 最終ジャッジ日時 | 2025-01-24 09:46:53 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#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";
}
potato167