답안 #500387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500387 2021-12-30T20:03:31 Z MohamedAhmed04 RMQ (NOI17_rmq) C++14
100 / 100
69 ms 11628 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1e5 + 10 ;

int n , q ;

int L[MAX] , R[MAX] , L2[MAX] , R2[MAX] ;

set<int>s , s2 ;

int ans[MAX] ;

void Exit()
{
	for(int i = 0 ; i < n ; ++i)
		cout<<-1<<" " ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>q ;
	for(int i = 0 ; i < n ; ++i)
		L[i] = R2[i] = -1 , R[i] = L2[i] = 1e9 ;
	while(q--)
	{
		int l , r , x ;
		cin>>l>>r>>x ;
		L[x] = max(L[x] , l) , R[x] = min(R[x] , r) ;
		L2[x] = min(L2[x] , l) , R2[x] = max(R2[x] , r) ;
	}
	for(int i = 0 ; i < n ; ++i)
		s.insert(i) , s2.insert(i) ;
	for(int i = n-1 ; i >= 0 ; --i)
	{
		if(L[i] == -1)
			continue ;
		if(L[i] > R[i])
			return Exit() , 0 ;
		auto it = s.lower_bound(L[i]) ;
		if(it == s.end() || (*it) > R[i])
			return Exit() , 0 ;
		ans[*it] = i , s.erase(it) , s2.erase(i) ;
		while(s.size())
		{
			it = s.lower_bound(L2[i]) ;
			if(it == s.end() || (*it) > R2[i])
				break ;
			int x = *s2.rbegin() ;
			if(x < i)
				return Exit() , 0 ;
			ans[*it] = x , s.erase(it) , s2.erase(x) ;
		}
	}
	while(s.size())
	{
		ans[*s.begin()] = *s2.begin() ;
		s.erase(s.begin()) , s2.erase(s2.begin()) ;
	}
	for(int i = 0 ; i < n ; ++i)
		cout<<ans[i]<<" " ;
	cout<<"\n" ;
	return 0 ;
}		
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 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 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 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 324 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 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 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 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 324 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 62 ms 9680 KB Output is correct
28 Correct 67 ms 10720 KB Output is correct
29 Correct 58 ms 10348 KB Output is correct
30 Correct 69 ms 11328 KB Output is correct
31 Correct 52 ms 8700 KB Output is correct
32 Correct 55 ms 8520 KB Output is correct
33 Correct 54 ms 10088 KB Output is correct
34 Correct 32 ms 6860 KB Output is correct
35 Correct 62 ms 11528 KB Output is correct
36 Correct 63 ms 11628 KB Output is correct
37 Correct 57 ms 11400 KB Output is correct
38 Correct 30 ms 7752 KB Output is correct
39 Correct 56 ms 10680 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 0 ms 332 KB Output is correct