题解:

一道比较简单的题目

容易发现状态数只有5*n个

而转移需要满足i1<i2;j1<j2

那么很明显是二维平面数点

暴力一点就是二维树状数组+map

5nlog^3 比较卡常

但是注意到我们的dp是保证了i1<i2的

所以本质是扫描线+树状数组

5nlogn

由于代码非常简单编译调试一遍过

代码:

#include <bits/stdc++.h>
using namespace std;
#define IL inline
#define rint register int
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--)
#define mid ((h+t)/2)
#define me(x) memset(x,0,sizeof(x))
#define lowbit(x) (x&(-x))
const int N=2e5;
int n,a[N],b[N],f[N][],cnt[N];
char ss[<<],*A=ss,*B=ss;
IL char gc()
{
return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;
}
template<class T>IL void read(T &x)
{
rint f=,c; while (c=gc(),c<||c>) if (c=='-') f=-; x=(c^);
while (c=gc(),<c&&c<) x=(x<<)+(x<<)+(c^); x*=f;
}
IL void maxx(int &x,int y)
{
if (x<y) x=y;
}
struct sgt{
int data[N];
int query(int x)
{
int ans=;
while (x)
{
maxx(ans,data[x]);
x-=lowbit(x);
}
return(ans);
}
void insert(int x,int y)
{
while (x<=n)
{
maxx(data[x],y);
x+=lowbit(x);
}
}
}S;
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
read(n); n*=;
rep(i,,n) read(a[i]);
rep(i,,n) read(b[i]);
rep(i,,n)
f[b[i]][++cnt[b[i]]]=i;
int ans=;
rep(i,,n)
dep(j,,)
{
int kk=S.query(f[a[i]][j]-)+;
S.insert(f[a[i]][j],kk);
maxx(ans,kk);
}
cout<<ans<<endl;
return ;
}

【bzoj1264】[AHOI2006]基因匹配Match 树状数组的更多相关文章

  1. bzoj1264 [AHOI2006]基因匹配Match 树状数组+lcs

    1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1255  Solved: 835[Submit][ ...

  2. BZOJ 1264: [AHOI2006]基因匹配Match 树状数组+DP

    1264: [AHOI2006]基因匹配Match Description 基因匹配(match) 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而成(地球 ...

  3. bzoj 1264: [AHOI2006]基因匹配Match (树状数组优化dp)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1264 思路: n大小为20000*5,而一般的dp求最长公共子序列复杂度是 n*n的,所以我 ...

  4. BZOJ_1264_[AHOI2006]基因匹配Match_树状数组

    BZOJ_1264_[AHOI2006]基因匹配Match_树状数组 Description 基因匹配(match) 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种 ...

  5. 洛谷P4303 [AHOI2006]基因匹配(树状数组)

    传送门 我已经连这种傻逼题都不会了orz 正常的dp是$O(n^2)$的,枚举第一个数组的$j$,然后第二个数组的$k$,如果相等,则$dp[i]=dp[j]+1$,否则$dp[i]=dp[j]$ 然 ...

  6. BZOJ1264: [AHOI2006]基因匹配Match

    1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 541  Solved: 347[Submit][S ...

  7. BZOJ1264 [AHOI2006]基因匹配Match 动态规划 树状数组

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1264 题意概括 给出两个长度为5*n的序列,每个序列中,有1~n各5个. 求其最长公共子序列长度. ...

  8. [BZOJ1264][AHOI2006]基因匹配Match(DP + 树状数组)

    传送门 有点类似LCS,可以把 a[i] 在 b 串中的位置用一个链式前向星串起来,由于链式前向星是从后往前遍历,所以可以直接搞. 状态转移方程 f[i] = max(f[j]) + 1 ( 1 &l ...

  9. BZOJ1264 [AHOI2006]基因匹配Match 【LCS转LIS】

    题目链接 BZOJ1264 题解 平凡的\(LCS\)是\(O(n^2)\)的 显然我们要根据题目的性质用一些不平凡的\(LCS\)求法 这就很巧妙了,, 我们考虑\(A\)序列的每个位置可能匹配\( ...

随机推荐

  1. Xml 文件读取

    .NET 读取Xml文件,用到XmlDocument类. 1.要获取文档的根: DocumentElement. 2.Attributes :获取 XmlAttributeCollection 包含此 ...

  2. 【转】HashMap实现原理及源码分析

    哈希表(hash table)也叫散列表,是一种非常重要的数据结构,应用场景极其丰富,许多缓存技术(比如memcached)的核心其实就是在内存中维护一张大的哈希表,而HashMap的实现原理也常常出 ...

  3. 2.4G和5G的Wi-Fi各自优缺点对比

    原文地址:http://service.tp-link.com.cn/detail_article_3366.html 1.为什么5G信号的穿墙效果比2.4G信号差? 与路由器的距离相同时,5G信号相 ...

  4. bootstrap4简单使用和入门02-bootstrap的js组件简单使用

    自带默认的css和js弹框控制 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  5. Mac 系统重新安装的几种方法

    转:https://blog.csdn.net/feibozhulang/article/details/43734109 苹果官网说明: https://support.apple.com/en-u ...

  6. Golang channel 特性

    最近在项目中遇到了 Go channel 的一些问题,在此记录下 close channel 的一些特性. 关闭channel ch := make(chan bool) close(ch) clos ...

  7. mysql生成数据字典

    git clone https://github.com/twindb/undrop-for-innodb.git make [root@redis01 undrop-for-innodb]# mak ...

  8. Golang的单引号、双引号与反引号

    Go语言的字符串类型string在本质上就与其他语言的字符串类型不同: Java的String.C++的std::string以及Python3的str类型都只是定宽字符序列 Go语言的字符串是一个用 ...

  9. hive学习01词频统计

    词频统计 #创建表,只有一列,列名line create table word_count ( line string) row format delimited fields terminated ...

  10. maven install 报错 No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    1.控制台打印信息 [INFO] Scanning for projects... [INFO] [INFO] ---------------------< org.cqupt.mauger:R ...