답안 #500385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500385 2021-12-30T20:02:06 Z MohamedAhmed04 RMQ (NOI17_rmq) C++14
0 / 100
1 ms 332 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] ;

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 cout<<-1<<"\n" , 0 ;
		auto it = s.lower_bound(L[i]) ;
		if(it == s.end() || (*it) > R[i])
			return cout<<-1<<"\n" , 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 cout<<-1<<"\n" , 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 328 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 Incorrect 1 ms 324 KB Unexpected end of file - int32 expected
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 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 Incorrect 1 ms 324 KB Unexpected end of file - int32 expected
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 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 Incorrect 1 ms 324 KB Unexpected end of file - int32 expected
7 Halted 0 ms 0 KB -