Submission #883026

# Submission time Handle Problem Language Result Execution time Memory
883026 2023-12-04T12:16:05 Z vjudge1 Exhibition (JOI19_ho_t2) C++14
100 / 100
746 ms 18808 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 8 ms 12124 KB Output is correct
2 Correct 9 ms 12124 KB Output is correct
3 Correct 9 ms 12124 KB Output is correct
4 Correct 9 ms 12124 KB Output is correct
5 Correct 10 ms 12224 KB Output is correct
6 Correct 9 ms 12120 KB Output is correct
7 Correct 10 ms 12124 KB Output is correct
8 Correct 9 ms 12124 KB Output is correct
9 Correct 10 ms 12124 KB Output is correct
10 Correct 11 ms 12080 KB Output is correct
11 Correct 8 ms 12124 KB Output is correct
12 Correct 11 ms 12040 KB Output is correct
13 Correct 10 ms 12124 KB Output is correct
14 Correct 10 ms 12124 KB Output is correct
15 Correct 6 ms 12124 KB Output is correct
16 Correct 10 ms 12124 KB Output is correct
17 Correct 9 ms 12124 KB Output is correct
18 Correct 10 ms 12120 KB Output is correct
19 Correct 10 ms 12216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12124 KB Output is correct
2 Correct 9 ms 12124 KB Output is correct
3 Correct 9 ms 12124 KB Output is correct
4 Correct 9 ms 12124 KB Output is correct
5 Correct 10 ms 12224 KB Output is correct
6 Correct 9 ms 12120 KB Output is correct
7 Correct 10 ms 12124 KB Output is correct
8 Correct 9 ms 12124 KB Output is correct
9 Correct 10 ms 12124 KB Output is correct
10 Correct 11 ms 12080 KB Output is correct
11 Correct 8 ms 12124 KB Output is correct
12 Correct 11 ms 12040 KB Output is correct
13 Correct 10 ms 12124 KB Output is correct
14 Correct 10 ms 12124 KB Output is correct
15 Correct 6 ms 12124 KB Output is correct
16 Correct 10 ms 12124 KB Output is correct
17 Correct 9 ms 12124 KB Output is correct
18 Correct 10 ms 12120 KB Output is correct
19 Correct 10 ms 12216 KB Output is correct
20 Correct 23 ms 12288 KB Output is correct
21 Correct 19 ms 12252 KB Output is correct
22 Correct 22 ms 12124 KB Output is correct
23 Correct 22 ms 12124 KB Output is correct
24 Correct 18 ms 12120 KB Output is correct
25 Correct 23 ms 12124 KB Output is correct
26 Correct 20 ms 12376 KB Output is correct
27 Correct 22 ms 12120 KB Output is correct
28 Correct 22 ms 12120 KB Output is correct
29 Correct 17 ms 12124 KB Output is correct
30 Correct 20 ms 12124 KB Output is correct
31 Correct 20 ms 12120 KB Output is correct
32 Correct 22 ms 12124 KB Output is correct
33 Correct 7 ms 12124 KB Output is correct
34 Correct 26 ms 12124 KB Output is correct
35 Correct 11 ms 12172 KB Output is correct
36 Correct 21 ms 12276 KB Output is correct
37 Correct 27 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12124 KB Output is correct
2 Correct 9 ms 12124 KB Output is correct
3 Correct 9 ms 12124 KB Output is correct
4 Correct 9 ms 12124 KB Output is correct
5 Correct 10 ms 12224 KB Output is correct
6 Correct 9 ms 12120 KB Output is correct
7 Correct 10 ms 12124 KB Output is correct
8 Correct 9 ms 12124 KB Output is correct
9 Correct 10 ms 12124 KB Output is correct
10 Correct 11 ms 12080 KB Output is correct
11 Correct 8 ms 12124 KB Output is correct
12 Correct 11 ms 12040 KB Output is correct
13 Correct 10 ms 12124 KB Output is correct
14 Correct 10 ms 12124 KB Output is correct
15 Correct 6 ms 12124 KB Output is correct
16 Correct 10 ms 12124 KB Output is correct
17 Correct 9 ms 12124 KB Output is correct
18 Correct 10 ms 12120 KB Output is correct
19 Correct 10 ms 12216 KB Output is correct
20 Correct 23 ms 12288 KB Output is correct
21 Correct 19 ms 12252 KB Output is correct
22 Correct 22 ms 12124 KB Output is correct
23 Correct 22 ms 12124 KB Output is correct
24 Correct 18 ms 12120 KB Output is correct
25 Correct 23 ms 12124 KB Output is correct
26 Correct 20 ms 12376 KB Output is correct
27 Correct 22 ms 12120 KB Output is correct
28 Correct 22 ms 12120 KB Output is correct
29 Correct 17 ms 12124 KB Output is correct
30 Correct 20 ms 12124 KB Output is correct
31 Correct 20 ms 12120 KB Output is correct
32 Correct 22 ms 12124 KB Output is correct
33 Correct 7 ms 12124 KB Output is correct
34 Correct 26 ms 12124 KB Output is correct
35 Correct 11 ms 12172 KB Output is correct
36 Correct 21 ms 12276 KB Output is correct
37 Correct 27 ms 12124 KB Output is correct
38 Correct 502 ms 18716 KB Output is correct
39 Correct 262 ms 16100 KB Output is correct
40 Correct 248 ms 16092 KB Output is correct
41 Correct 426 ms 17132 KB Output is correct
42 Correct 284 ms 18720 KB Output is correct
43 Correct 294 ms 18652 KB Output is correct
44 Correct 463 ms 18572 KB Output is correct
45 Correct 745 ms 18744 KB Output is correct
46 Correct 535 ms 18716 KB Output is correct
47 Correct 479 ms 18404 KB Output is correct
48 Correct 334 ms 17864 KB Output is correct
49 Correct 488 ms 17660 KB Output is correct
50 Correct 396 ms 17660 KB Output is correct
51 Correct 344 ms 18712 KB Output is correct
52 Correct 386 ms 18712 KB Output is correct
53 Correct 536 ms 18712 KB Output is correct
54 Correct 261 ms 16572 KB Output is correct
55 Correct 494 ms 18568 KB Output is correct
56 Correct 287 ms 17872 KB Output is correct
57 Correct 36 ms 12884 KB Output is correct
58 Correct 77 ms 15412 KB Output is correct
59 Correct 304 ms 17912 KB Output is correct
60 Correct 44 ms 13008 KB Output is correct
61 Correct 243 ms 16416 KB Output is correct
62 Correct 746 ms 18748 KB Output is correct
63 Correct 671 ms 18712 KB Output is correct
64 Correct 708 ms 18808 KB Output is correct
65 Correct 692 ms 18636 KB Output is correct
66 Correct 688 ms 18640 KB Output is correct
67 Correct 685 ms 18580 KB Output is correct
68 Correct 715 ms 18720 KB Output is correct
69 Correct 541 ms 17200 KB Output is correct
70 Correct 643 ms 18568 KB Output is correct
71 Correct 363 ms 16648 KB Output is correct
72 Correct 398 ms 16588 KB Output is correct
73 Correct 280 ms 16248 KB Output is correct