結果

問題 No.1675 Strange Minimum Query
ユーザー 沙耶花
提出日時 2021-09-10 21:40:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 1,232 bytes
コンパイル時間 5,314 ms
コンパイル使用メモリ 259,620 KB
最終ジャッジ日時 2025-01-24 09:58:33
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf("%d %d %d",&l[i],&r[i],&b[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

using P = pair<int,int>;

P op(P a,P b){
	return max(a,b);
}

P e(){
	return make_pair(-Inf,-1);
}

int op2(int a,int b){
	return min(a,b);
}
int e2(){
	return Inf;
}

int main(){
	
	int n,q;
	cin>>n>>q;
	vector<P> temp(n);
	rep(i,n){
		temp[i] = make_pair(Inf,i);
	}
	segtree<P,op,e> seg(temp);
	
	vector<int> l(q),r(q),b(q);
	rep(i,q){
		scanf("%d %d %d",&l[i],&r[i],&b[i]);
		l[i]--;
	}
	vector<int> t(q);
	rep(i,q)t[i] = i;
	
	sort(t.rbegin(),t.rend(),[&](int x,int y){
		return b[x]<b[y];
	});
	
	rep(i,q){
		int ind = t[i];
		while(true){
			P ret = seg.prod(l[ind],r[ind]);
			if(ret.first!=Inf)break;
			seg.set(ret.second,make_pair(b[ind],ret.second));
		}
	}
	
	while(true){
		P ret = seg.prod(0,n);
		if(ret.first!=Inf)break;
		seg.set(ret.second,make_pair(1000000000,0));
		
	}
	segtree<int,op2,e2> seg2(n);
	rep(i,n){
		seg2.set(i,seg.get(i).first);
	}
	rep(i,q){
		if(seg2.prod(l[i],r[i])!=b[i]){
			cout<<-1<<endl;
			return 0;
		}
		
	}
	
	rep(i,n){
		if(i!=0)cout<<' ';
		cout<<seg.get(i).first;
	}
	cout<<endl;
	
		
	
	return 0;
}
0