Submission #883166

# Submission time Handle Problem Language Result Execution time Memory
883166 2023-12-04T17:07:45 Z NotLinux Exhibition (JOI19_ho_t2) C++17
100 / 100
934 ms 20652 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;//wrong yerse N i değiştirmeyi unutma
const int inf = 1e9 + 7;
struct SEGT{
	vector < int > tree;
	int sz;
	SEGT(int x){
		sz = x+3;
		tree.assign(4*sz , inf);
	}
	int _query(int ind , int l , int r , int ql , int qr){
		if(l >= ql and r <= qr)return tree[ind];
		else if(l > qr or r < ql)return inf;
		int mid = (l+r)/2;
		return min(_query(ind*2,l,mid,ql,qr) , _query(ind*2+1,mid+1,r,ql,qr));
	}
	int query(int l , int r){
		return _query(1,1,sz,l,r);
	}
	void _update(int ind , int l , int r , int qp , int qv){
		if(l == r){
			tree[ind] = qv;
			return;
		}
		int mid = (l+r)/2;
		if(mid >= qp)_update(ind*2,l,mid,qp,qv);
		else _update(ind*2+1,mid+1,r,qp,qv);
		tree[ind] = min(tree[ind*2] , tree[ind*2+1]);
	}
	void update(int p , int v){
		_update(1,1,sz,p,v);
	}
};
int n , m , frame[N];
pair < int , int > picture[N];
vector < int > comp;
bool check(int x){
	SEGT segt(N);
	vector < int > ind[N];
	for(int i = 0;i<n;i++){
		ind[picture[i].second].push_back(i);
	}
	for(int i = 0;i<N;i++){
		if(ind[i].size()){
			sort(ind[i].begin() , ind[i].end());
			reverse(ind[i].begin() , ind[i].end());
			segt.update(i,ind[i].back());
		}
	}
	int last = 0;
	for(int i = m-x;i<m;i++){
		int nxt = segt.query(1,frame[i]);
		if(nxt == inf)return 0;
		while(last <= nxt){
			ind[picture[last].second].pop_back();
			if(ind[picture[last].second].size()){
				segt.update(picture[last].second , ind[picture[last].second].back());
			}
			else{
				segt.update(picture[last].second , inf);
			}
			last++;
		}
	}
	return 1;
}
void solve(){
	cin >> n >> m;
	for(int i = 0;i<n;i++){
		cin >> picture[i].second >> picture[i].first;
		comp.push_back(picture[i].second);
	}
	for(int i = 0;i<m;i++){
		cin >> frame[i];
		comp.push_back(frame[i]);
	}
	sort(comp.begin() , comp.end());
	comp.resize(unique(comp.begin() , comp.end()) - comp.begin());
	for(int i = 0;i<n;i++){
		picture[i].second = lower_bound(comp.begin() , comp.end() , picture[i].second) - comp.begin() + 1;
	}
	for(int i = 0;i<m;i++){
		frame[i] = lower_bound(comp.begin() , comp.end() , frame[i]) - comp.begin() + 1;
	}

	sort(frame , frame + m);
	sort(picture , picture + n);
	int l = 0 , r = n+1 , ans = 0;
	while(l < r){
		int mid = (l+r)/2;
		if(check(mid)){
			ans = mid;
			l = mid+1;
		}
		else r = mid;
	}
	cout << ans << endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 9 ms 12128 KB Output is correct
3 Correct 11 ms 12124 KB Output is correct
4 Correct 13 ms 12124 KB Output is correct
5 Correct 14 ms 12120 KB Output is correct
6 Correct 9 ms 12192 KB Output is correct
7 Correct 11 ms 12124 KB Output is correct
8 Correct 9 ms 12124 KB Output is correct
9 Correct 11 ms 12124 KB Output is correct
10 Correct 11 ms 12124 KB Output is correct
11 Correct 9 ms 12124 KB Output is correct
12 Correct 12 ms 12208 KB Output is correct
13 Correct 11 ms 12124 KB Output is correct
14 Correct 10 ms 12224 KB Output is correct
15 Correct 7 ms 12124 KB Output is correct
16 Correct 12 ms 12124 KB Output is correct
17 Correct 10 ms 12220 KB Output is correct
18 Correct 11 ms 12152 KB Output is correct
19 Correct 10 ms 12120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 9 ms 12128 KB Output is correct
3 Correct 11 ms 12124 KB Output is correct
4 Correct 13 ms 12124 KB Output is correct
5 Correct 14 ms 12120 KB Output is correct
6 Correct 9 ms 12192 KB Output is correct
7 Correct 11 ms 12124 KB Output is correct
8 Correct 9 ms 12124 KB Output is correct
9 Correct 11 ms 12124 KB Output is correct
10 Correct 11 ms 12124 KB Output is correct
11 Correct 9 ms 12124 KB Output is correct
12 Correct 12 ms 12208 KB Output is correct
13 Correct 11 ms 12124 KB Output is correct
14 Correct 10 ms 12224 KB Output is correct
15 Correct 7 ms 12124 KB Output is correct
16 Correct 12 ms 12124 KB Output is correct
17 Correct 10 ms 12220 KB Output is correct
18 Correct 11 ms 12152 KB Output is correct
19 Correct 10 ms 12120 KB Output is correct
20 Correct 21 ms 12296 KB Output is correct
21 Correct 19 ms 12120 KB Output is correct
22 Correct 27 ms 12296 KB Output is correct
23 Correct 20 ms 12296 KB Output is correct
24 Correct 20 ms 12296 KB Output is correct
25 Correct 20 ms 12300 KB Output is correct
26 Correct 20 ms 12300 KB Output is correct
27 Correct 19 ms 12380 KB Output is correct
28 Correct 26 ms 12304 KB Output is correct
29 Correct 24 ms 12124 KB Output is correct
30 Correct 27 ms 12296 KB Output is correct
31 Correct 26 ms 12296 KB Output is correct
32 Correct 24 ms 12120 KB Output is correct
33 Correct 7 ms 12124 KB Output is correct
34 Correct 23 ms 12252 KB Output is correct
35 Correct 12 ms 12124 KB Output is correct
36 Correct 21 ms 12300 KB Output is correct
37 Correct 21 ms 12300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12124 KB Output is correct
2 Correct 9 ms 12128 KB Output is correct
3 Correct 11 ms 12124 KB Output is correct
4 Correct 13 ms 12124 KB Output is correct
5 Correct 14 ms 12120 KB Output is correct
6 Correct 9 ms 12192 KB Output is correct
7 Correct 11 ms 12124 KB Output is correct
8 Correct 9 ms 12124 KB Output is correct
9 Correct 11 ms 12124 KB Output is correct
10 Correct 11 ms 12124 KB Output is correct
11 Correct 9 ms 12124 KB Output is correct
12 Correct 12 ms 12208 KB Output is correct
13 Correct 11 ms 12124 KB Output is correct
14 Correct 10 ms 12224 KB Output is correct
15 Correct 7 ms 12124 KB Output is correct
16 Correct 12 ms 12124 KB Output is correct
17 Correct 10 ms 12220 KB Output is correct
18 Correct 11 ms 12152 KB Output is correct
19 Correct 10 ms 12120 KB Output is correct
20 Correct 21 ms 12296 KB Output is correct
21 Correct 19 ms 12120 KB Output is correct
22 Correct 27 ms 12296 KB Output is correct
23 Correct 20 ms 12296 KB Output is correct
24 Correct 20 ms 12296 KB Output is correct
25 Correct 20 ms 12300 KB Output is correct
26 Correct 20 ms 12300 KB Output is correct
27 Correct 19 ms 12380 KB Output is correct
28 Correct 26 ms 12304 KB Output is correct
29 Correct 24 ms 12124 KB Output is correct
30 Correct 27 ms 12296 KB Output is correct
31 Correct 26 ms 12296 KB Output is correct
32 Correct 24 ms 12120 KB Output is correct
33 Correct 7 ms 12124 KB Output is correct
34 Correct 23 ms 12252 KB Output is correct
35 Correct 12 ms 12124 KB Output is correct
36 Correct 21 ms 12300 KB Output is correct
37 Correct 21 ms 12300 KB Output is correct
38 Correct 508 ms 20508 KB Output is correct
39 Correct 280 ms 18076 KB Output is correct
40 Correct 322 ms 17896 KB Output is correct
41 Correct 451 ms 18928 KB Output is correct
42 Correct 293 ms 20512 KB Output is correct
43 Correct 306 ms 20520 KB Output is correct
44 Correct 490 ms 20516 KB Output is correct
45 Correct 818 ms 20508 KB Output is correct
46 Correct 533 ms 20508 KB Output is correct
47 Correct 499 ms 20028 KB Output is correct
48 Correct 348 ms 19312 KB Output is correct
49 Correct 593 ms 18952 KB Output is correct
50 Correct 408 ms 18944 KB Output is correct
51 Correct 333 ms 20512 KB Output is correct
52 Correct 404 ms 20508 KB Output is correct
53 Correct 586 ms 20508 KB Output is correct
54 Correct 256 ms 18284 KB Output is correct
55 Correct 503 ms 20652 KB Output is correct
56 Correct 292 ms 19156 KB Output is correct
57 Correct 38 ms 13668 KB Output is correct
58 Correct 77 ms 16776 KB Output is correct
59 Correct 311 ms 19224 KB Output is correct
60 Correct 45 ms 13812 KB Output is correct
61 Correct 284 ms 17440 KB Output is correct
62 Correct 777 ms 20512 KB Output is correct
63 Correct 923 ms 20512 KB Output is correct
64 Correct 932 ms 20516 KB Output is correct
65 Correct 784 ms 20512 KB Output is correct
66 Correct 934 ms 20448 KB Output is correct
67 Correct 806 ms 20508 KB Output is correct
68 Correct 860 ms 20516 KB Output is correct
69 Correct 626 ms 18768 KB Output is correct
70 Correct 813 ms 20500 KB Output is correct
71 Correct 380 ms 18232 KB Output is correct
72 Correct 418 ms 18476 KB Output is correct
73 Correct 282 ms 17900 KB Output is correct