99292024-03-18 18:33:39111Hadjáratcpp17Wrong answer 29/100284ms63364 KiB
#include <bits/stdc++.h>
using namespace std;

struct BST {
	multimap<int,int>m;

	void insert(int key, int val) {
		auto it=m.emplace(key,val);
		if(it!=m.begin()&&it->second<=prev(it)->second){
			m.erase(it);
			return;
		}
		it++;
		while(it!=m.end()&&val>=it->second){
			it=m.erase(it);
		}
	}

	int range_max(int kk, int k) {
		auto it=m.upper_bound(k);
		if(it==m.begin())return 0;
		return prev(it)->second;
	}
};

BST s[400001];

void insert(int i,int l,int r,int x,int y,int v){
	if(l>x||r<x){
		return;
	}
	s[i].insert(y,v);
	if(l==r){
		return;
	}
	insert(i*2+1,l,(l+r)/2,x,y,v);
	insert(i*2+2,(l+r)/2+1,r,x,y,v);
}

int query_max(int i,int l,int r,int x0,int y0,int x1,int y1){
	if(l>x1||r<x0){
		return 0;
	}
	if(l>=x0&&r<=x1){
		return s[i].range_max(y0,y1);
	}
	int ans1=query_max(i*2+1,l,(l+r)/2,x0,y0,x1,y1);
	int ans2=query_max(i*2+2,(l+r)/2+1,r,x0,y0,x1,y1);
	return max(ans1,ans2);
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef CB
	freopen("be2.txt","r",stdin);
//	freopen("out.txt","w",stdout);
#endif
	int N;
	cin>>N;
	vector<int>r(N),a(N);
	for(int i=0;i<N;i++){
		cin>>r[i]>>a[i];
	}
	auto w=r;
	sort(w.begin(),w.end());
	for(int i=0;i<N;i++){
		r[i]=lower_bound(w.begin(),w.end(),r[i])-w.begin()+1;
	}
	int ans=0;
	for(int i=0;i<N;i++){
		int v=query_max(0,1,100000,1,1,r[i]-1,a[i]-1)+1;
		insert(0,1,100000,r[i],a[i],v);
		ans=max(ans,v);
	}
	cout<<ans<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base29/100
1Wrong answer0/016ms39400 KiB
2Time limit exceeded0/0284ms62164 KiB
3Partially correct2/416ms39856 KiB
4Partially correct2/416ms39944 KiB
5Partially correct2/419ms40016 KiB
6Partially correct2/417ms40264 KiB
7Partially correct2/416ms40476 KiB
8Partially correct2/416ms40532 KiB
9Partially correct2/416ms40668 KiB
10Partially correct2/418ms41228 KiB
11Partially correct2/434ms43132 KiB
12Partially correct2/459ms45616 KiB
13Partially correct3/654ms45596 KiB
14Partially correct3/6101ms49612 KiB
15Partially correct3/6157ms54892 KiB
16Time limit exceeded0/6261ms31108 KiB
17Time limit exceeded0/6245ms32484 KiB
18Time limit exceeded0/6254ms63364 KiB
19Time limit exceeded0/6240ms63124 KiB
20Time limit exceeded0/6237ms63108 KiB
21Time limit exceeded0/6225ms62876 KiB
22Time limit exceeded0/6223ms62636 KiB