답안 #497097

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497097 2021-12-22T11:32:33 Z MohamedAhmed04 Exhibition (JOI19_ho_t2) C++14
0 / 100
1 ms 460 KB
#include <bits/stdc++.h>

using namespace std ;

struct segtree
{
	vector<int>tree ;
	int sz ;
	void init(int sz2)
	{
		sz = sz2 + 2 ;
		tree = vector<int>(sz*4 , 0) ;
	}

	int Merge(int &x , int &y)
	{
		return max(x , y) ;
	}

	void update(int node , int l , int r , int idx , int val)
	{
		if(idx > r || idx < l)
			return ; 
		if(l == r)
		{
			tree[node] = max(tree[node] , val) ;
			return ;
		}
		int mid = (l + r) >> 1 ;
		update(node << 1 , l , mid , idx , val) ;
		update(node << 1 | 1 , mid+1 , r , idx , val) ;
		tree[node] = Merge(tree[node << 1] , tree[node << 1 | 1]) ;
	}

	int query(int node , int l , int r , int from , int to)
	{
		if(from > r || to < l)
			return 0 ;
		if(l >= from && r <= to)
			return tree[node] ;
		int mid = (l + r) >> 1 ;
		auto x = query(node << 1 , l , mid , from , to) ;
		auto y = query(node << 1 | 1 , mid+1 , r , from , to) ;
		return Merge(x , y) ;
	}

	void update(int idx , int x)
	{
		update(1 , 0 , sz , idx , x) ;
	}

	int query(int l , int r)
	{
		return query(1 , 0 , sz , l , r) ; 
	}
};

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n , m ;

vector< pair<int , int> >vp ;

void compress()
{
	vector<int>v ;
	for(auto &p : vp)
		v.push_back(p.second) ;
	sort(v.begin() , v.end()) ;
	v.erase(unique(v.begin() , v.end()) , v.end()) ;
	for(auto &p : vp)
	{
		p.second = lower_bound(v.begin() , v.end() , p.second) - v.begin() ;
		p.second++ ;
	}
}

bool check(int x)
{
	segtree tree ;
	for(auto &p : vp)
	{
		int a = tree.query(1 , p.second) ;
		int idx = x + a ;
		if(idx >= 0 && arr[idx] < p.first)
			continue ;
		if(idx == m-1)
			return true ;
		tree.update(p.second , a+1) ;
	}
	return false ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < n ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		vp.emplace_back(x , y) ;
	}
	for(int i = 0 ; i < m ; ++i)
		cin>>arr[i] ;
	compress() ;
	sort(vp.begin() , vp.end()) ;
	sort(arr , arr+m) ;
	int l = 0 , r = m-1 ;
	int ans = 0 ;
	while(l <= r)
	{
		int mid = (l + r) >> 1 ;
		if(check(mid))
			ans = m-mid , r = mid-1 ;
		else
			l = mid+1 ;
	}
	return cout<<ans<<"\n" , 0 ;
}		
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -