답안 #426778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426778 2021-06-14T09:47:18 Z nots0fast RMQ (NOI17_rmq) C++17
100 / 100
81 ms 14036 KB
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define ld long double
#define MAX (int)(pow(10,6) + 10)
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9) + 7;

void badcase(ll n){
	fori(n){
		cout<<-1<<' ';
	}
}

bool srt(vector<ll>& a, vector<ll>& b){
	if(a[1] != b[1]){
		return a[1] < b[1];
	}
	return a[0] < b[0];
}

void deal(){
	ll n, m;
	cin>>n>>m;
	vector<vector<pair<ll, ll> > > all(n);
	fori(m){
		ll li, ri, v;
		cin>>li>>ri>>v;
		all[v].pb(mp(li, ri));
	}
	
	vector<pair<ll,ll> > res(n);
	vector<ll> arr(n, -1);
	
	fori(n){
		res[i] = mp(-1, -1);
		if((ll)all[i].size() == 0){
			continue;
		}
		ll l = -1, r = n+1;
		for(auto& el : all[i]){
			l = max(l, el.ff);
			r = min(r, el.ss);
		}
		if(l > r){
			badcase(n);
			return;
		}
		res[i] = mp(l, r);
	}
	
	set<ll> free;
	fori(n){
		free.insert(i);
	}
	
	vector<vector<ll> > toadd(n);
	
	for(ll i = n-1; i>-1; i--){
		if((ll)free.size() < i+1){
			badcase(n);
			return;
		}
		if(res[i].ff == -1){
			continue;
		}
		{
			ll l = res[i].ff, r = res[i].ss;
			auto it = free.lower_bound(l);
			if(it == free.end() || (*it) > r){
				badcase(n);
				return;
			}
			arr[*it] = i;
			free.erase(it);
		}
		for(auto& el : all[i]){
			ll l = el.ff, r  =el.ss;
			auto it = free.lower_bound(l);
			while(it!=free.end() && (*it) <= r){
				auto itn = it;
				++itn;
				toadd[i].pb(*it);
				free.erase(it);
				it = itn;
			}
		}
	}
	
	fori(n){
		for(auto& el: toadd[i]){
			free.insert(el);
		}
		if(res[i].ff == -1){
			auto it = free.begin();
			arr[*it] = i;
			free.erase(it);
		}
	}
	
	
	
	
	fori(n){
		cout<<arr[i]<<' ';
	}
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}















# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 73 ms 10880 KB Output is correct
28 Correct 75 ms 13188 KB Output is correct
29 Correct 68 ms 12344 KB Output is correct
30 Correct 81 ms 14036 KB Output is correct
31 Correct 61 ms 10924 KB Output is correct
32 Correct 66 ms 10744 KB Output is correct
33 Correct 54 ms 11156 KB Output is correct
34 Correct 34 ms 7620 KB Output is correct
35 Correct 60 ms 12968 KB Output is correct
36 Correct 32 ms 7228 KB Output is correct
37 Correct 43 ms 8132 KB Output is correct
38 Correct 32 ms 8236 KB Output is correct
39 Correct 32 ms 6928 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 332 KB Output is correct