99272024-03-18 18:28:15111Hadjáratcpp17Runtime error 0/10032ms65004 KiB
#include <bits/stdc++.h>
using namespace std;

struct BST {
	multimap<int,int>m;

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

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

BST s[4000005];

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];
	}
	int ans=0;
	for(int i=0;i<N;i++){
		int v=query_max(0,1,1000000,1,1,r[i]-1,a[i]-1)+1;
		insert(0,1,1000000,r[i],a[i],v);
		ans=max(ans,v);
	}
	cout<<ans<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Runtime error0/032ms65004 KiB
2Runtime error0/032ms64764 KiB
3Runtime error0/432ms64528 KiB
4Runtime error0/432ms64288 KiB
5Runtime error0/432ms64188 KiB
6Runtime error0/427ms63948 KiB
7Runtime error0/427ms63708 KiB
8Runtime error0/427ms63700 KiB
9Runtime error0/432ms63472 KiB
10Runtime error0/432ms63212 KiB
11Runtime error0/426ms62972 KiB
12Runtime error0/426ms62732 KiB
13Runtime error0/625ms62728 KiB
14Runtime error0/625ms62720 KiB
15Runtime error0/627ms62708 KiB
16Runtime error0/626ms62472 KiB
17Runtime error0/630ms62464 KiB
18Runtime error0/626ms62460 KiB
19Runtime error0/630ms62236 KiB
20Runtime error0/630ms62232 KiB
21Runtime error0/629ms62096 KiB
22Runtime error0/626ms61868 KiB