蒟蒻的思路来自于老师讲的思路,若和别的题解差不多,勿喷 QWQ。
Solution
前置芝士:
Dilworth 定理(狄尔沃斯定理),是关于偏序集的定理:对于任意有限偏序集,其最大反链中元素个数必等于最小链覆盖中链的数目,详情戳这,主要看Dilworth 定理。
题目思路
分别输入 , 表示在第 秒时,需要按下按钮 。
若同一只手能在 和 时按到 和 ,那我们不妨令 ,则有 ,去绝对值得:
接着移项:
我们不妨把每个 , 看做一个二元组:。因此,我们现在只需求出二元组的最小链覆盖就可以了。
考虑Dilworth定理,对于任意有限偏序集,其最大反链中元素个数必等于最小链覆盖中链的数目。
我们将每个二元组第一项升序排序,求出第二项的最大反链,再动态更新反链中的元素个数做为答案就好了,接下来是你们最喜欢的代码!
AC code
//本人马蜂不太行,不喜勿喷
//防抄袭代码已加入QWQ
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5; //数组开大点
struct node
{
int x,y;
}a[N]; //结构体node
char buf[500005],*p1,*p2;
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,100000,stdin),p1 == p2) ? EOF : *p1++)
inline int read()
{
int x = 0,flag = 1;
char ch = gc();
for(;!isdigit(ch);ch = gc()) if(ch == '-') flag = -1;
for(;isdigit(ch);ch = gc()) x = x * 10 + (ch ^ 48);
return x * flag;
}
inline void write(int x)
{
if(x < 0) putchar('-'),x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
return ;
} //快读快写,不说了
int n,m,ans;
int save[N]; //辅助求解最长反链
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
n = read();m = read();
for(int i = 1;i <= m;i++) a[i].x = read();
for(int i = 1;i <= m;i++) a[i].y = read();
for(int i = 1;i <= m;i++) a[i] = {a[i].x - a[i].y,a[i].x + a[i].y};
sort(a + 1,a + m + 1,[](node x,node y)
{
return x.x == y.x ? x.y < y.y : x.x > y.x;
}); //排序(老师教的特殊写法)
for(int i = 1;i <= m;i++)
{
int id = lower_bound(save + 1,save + ans + 1,a[i].y) - save;
save[id] = a[i].y;
ans = max(ans,2);
}
write(ans);
}完结撒花
无耻求赞 AWA,管理员求过 QWQ。