WA on #4 91pts
查看原帖
WA on #4 91pts
1328264
wjy7777楼主2025/8/4 16:27

本人要上课,晚上回

A了,但是下样例(bushi

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,dp[100009],ans;
struct node{
	int l,y;
}a[1000005];
bool cmp(node x,node r){
	return x.l!=r.l ? x.l>r.l : x.y>=r.y;
}
int main(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i].l>>a[i].y;
	}
//	if(n==3&&a[1].l==1&&a[1].y==3){
//		cout<<3;
//		return 0;
//	}
	sort(a+1,a+n+1,cmp);
	dp[1]=a[1].y;
	for(int i=2;i<=n;i++)
	{
		int l=1,r=ans;
		while (l<=r){
			int mid=(l+r)/2;
			if (dp[mid]<a[i].y){
				l=mid+1;
			}
			else{
				r=mid-1;
			}
		}	
		dp[l]=a[i].y;
		if(l==ans+1)ans++;
	}
	cout<<ans;
	return 0;
}

调好必关!

2025/8/4 16:27
加载中...