luogu P5939 [POI1998]折线
题面传送门
首先这个\([45,-45]\)看上去就很不爽,于是顺时针旋转45一下然后变成\([0,90]\)
然后就发现一个点只能被它左上角的点的折线拉到。
那么就是求覆盖所有点的不升字符列最少个数,经典转化一下就是最长上升子序列长度。
直接树状数组就好了。
code:
#include<bits/stdc++.h>
#define I inline
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define re register
#define RI re int
#define ll long long
#define db double
#define lb long db
#define N 30000
#define K 50
#define mod 998244353
#define Mod 998244352
#define eps (1e-4)
#define U unsigned int
#define it iterator
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define d(x,y) (n*(x-1)+(y))
using namespace std;
int n,m,k,dp[N+5],Minn=1e9,x,y,Ans,Maxn;
struct Ques{int x,y;}S[N+5];I bool cmp(Ques x,Ques y){return x.x==y.x?x.y>y.y:x.x<y.x;}
struct Tree{
int F[N+5<<2];I void Get(int x,int y){while(x<=Maxn-Minn)F[x]=max(F[x],y),x+=x&-x;}I int Query(int x){int Ans=0;while(x) Ans=max(Ans,F[x]),x-=x&-x;return Ans;}
}T;
int main(){
freopen("1.in","r",stdin);
re int i;scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d%d",&x,&y),S[i].x=y-x,S[i].y=y+x,Minn=min(Minn,S[i].y),Maxn=max(Maxn,S[i].y);sort(S+1,S+n+1,cmp);Minn--;
for(i=1;i<=n;i++)dp[i]=T.Query(S[i].y-Minn-1)+1,T.Get(S[i].y-Minn,dp[i]),Ans=max(Ans,dp[i]);printf("%d\n",Ans);
}