51nod-3976-最长序列
https://class.51nod.com/Html/Textbook/ChapterIndex.html#textbookId=126&chapterId=338
https://class.51nod.com/Html/Textbook/Problem.html#problemId=3976&textbookChapterId=725
LIS是符号只有大于或小于,所以这道题就是LIS问题。
状态设计同LIS,由于答案就是长度,所以就能知道是哪一种符号了。
多种符号,所以不能使用贪心优化。
但是可以使用树状数组求前缀max。
<的直接查询,>的反转大小,=的开个数组max即可。
不需要离散化。
传递性,所以
#include<iostream>
#include<algorithm>
using namespace std;
const int N=500010,M=1000010,L=M-9;
int n,k,a[N],f[N],same[M];
char s[N];
struct BIT{
int c[M];
void add(int x,int v){
for(;x<L;x+=x&-x)c[x]=max(c[x],v);
}
int sum(int x){
int res=0;
for(;x;x-=x&-x)res=max(res,c[x]);
return res;
}
}le,ge;
int main(){
#ifdef LOCAL
freopen("1.txt","r",stdin);
#endif
#ifndef LOCAL
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
#endif
cin>>n>>k;
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=k;++i)cin>>s[i];
int ans=1;
for(int i=1;i<=n;++i){
int &sam=same[a[i]];
ans=max(f[i]=max({le.sum(a[i]-1),ge.sum(L-a[i]-1),sam})+1,ans);
char op=s[(f[i]-1)%k+1];
if(op=='=')sam=max(sam,f[i]);
else if(op=='<')le.add(a[i],f[i]);
else ge.add(L-a[i],f[i]);
}
cout<<ans;
return 0;
}
本文作者:wscqwq
本文链接:https://www.cnblogs.com/wscqwq/p/18327153
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步