답안 #532845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532845 2022-03-04T05:28:34 Z amunduzbaev Exhibition (JOI19_ho_t2) C++17
0 / 100
2 ms 3404 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long


const int N = 1e5 + 5;
struct ST{
	int tree[N << 2];
	
	void sett(int i, int v, int lx = 0, int rx = N, int x = 1){
		if(lx == rx) { tree[x] = max(tree[x], v); return; }
		int m = (lx + rx) >> 1;
		if(i <= m) sett(i, v, lx, m, x<<1);
		else sett(i, v, m+1, rx, x<<1|1);
		tree[x] = max(tree[x<<1], tree[x<<1|1]);
	}
	
	int get(int l, int r, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return 0;
		if(lx >= l && rx <= r) return tree[x];
		int m = (lx + rx) >> 1;
		return max(get(l, r, lx, m, x<<1), get(l, r, m+1, rx, x<<1|1));
	}
}tree;

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m; cin>>n>>m;
	vector<int> s(n), v(n), c(m), p(n);
	for(int i=0;i<n;i++) cin>>s[i]>>v[i], p[i] = i;
	sort(p.begin(), p.end(), [&](int i, int j){
		return (v[i] < v[j]);
	});
	
	for(int i=0, last=0;i<n;){
		int j=i;
		while(j<n && v[p[i]] == v[p[j]]) j++;
		while(i<j) v[p[i++]] = last;
		last++;
	}
	
	for(int i=0;i<m;i++){
		cin>>c[i];
	} sort(c.begin(), c.end());
	vector<int> left(n);
	for(int i=0;i<n;i++){
		left[i] = m - (int)(lower_bound(c.begin(), c.end(), s[i]) - c.begin()) - 1;
	}
	
	vector<ar<int, 2>> t(n);
	for(int i=0;i<n;i++) t[i] = {v[p[i]], left[p[i]]};
	for(int i=0;i<n;i++) v[i] = t[i][0], left[i] = t[i][1];
	
	//~ for(int i=0;i<n;i++) cout<<left[i]<<" ";
	//~ cout<<"\n";
	//~ for(int i=0;i<n;i++) cout<<v[i]<<" ";
	//~ cout<<"\n";
	
	auto check = [&](int k){
		memset(tree.tree, 0, sizeof tree.tree);
		vector<int> dp(n);
		for(int i=0;i<n;i++){
			if(left[i] == -1) continue;
			dp[i] = tree.get(0, v[i]) + 1;
			int p = max(1ll, k - left[i]);
			if(dp[i] >= p){
				tree.sett(v[i], dp[i]);
			}
		} return (tree.get(0, N) >= k);
	};
	
	int l = 0, r = n;
	while(l < r){
		int m = (l + r + 1) >> 1;
		if(check(m)) l = m;
		else r = m - 1;
	}
	
	cout<<l<<"\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Incorrect 2 ms 3388 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Incorrect 2 ms 3388 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Incorrect 2 ms 3388 KB Output isn't correct
4 Halted 0 ms 0 KB -