[BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II
Description
Input
Output
Sample Input
1
2
3
4
5
6
6
5
4
3
2
1
Sample Output
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define reg register
inline char gc() {
static const int bs = << ;
static unsigned char buf[bs], *st, *ed;
if (st == ed) ed = buf + fread(st = buf, , bs, stdin);
return st == ed ? EOF : *st++;
}
#define gc getchar
inline int read() {
int res=;char ch=gc();bool fu=;
while(!isdigit(ch))fu|=(ch=='-'), ch=gc();
while(isdigit(ch))res=(res<<)+(res<<)+(ch^), ch=gc();
return fu?-res:res;
}
#define N 100005
int n;
int a[N], b[N];
int pos[N];
int c[N*], cnt, tmp[];
int low[N*], ans; int main()
{
n = read();
for (reg int i = ; i <= n ; i ++) a[i] = read();
for (reg int i = ; i <= n ; i ++) pos[b[i] = read()] = i;
for (reg int i = ; i <= n ; i ++)
{
int top = ;
for (reg int j = max(, a[i] - ) ; j <= min(n, a[i] + ) ; j ++)
tmp[++top] = pos[j];
sort(tmp + , tmp + + top);
for (reg int j = top ; j >= ; j --) c[++cnt] = tmp[j];
}
low[++ans] = c[];
for (reg int i = ; i <= cnt ; i ++)
{
if (c[i] > low[ans]) low[++ans] = c[i];
else {
int t = lower_bound(low + , low + + ans, c[i]) - low;
low[t] = c[i];
}
}
cout << ans << endl;
return ;
}
[BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II的更多相关文章
- [BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II dp
4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II Time Limit: 10 Sec Memory Limit: 128 MBSubmi ...
- BZOJ4990 [Usaco2017 Feb]Why Did the Cow Cross the Road II 动态规划 树状数组
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4990 题意概括 有上下两行长度为 n 的数字序列 A 和序列 B,都是 1 到 n 的排列,若 a ...
- 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 线段树维护dp
题目 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 链接 http://www.lydsy.com/JudgeOnline/proble ...
- BZOJ4993 [Usaco2017 Feb]Why Did the Cow Cross the Road II 动态规划 树状数组
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4993 题意概括 有上下两行长度为 n 的数字序列 A 和序列 B,都是 1 到 n 的排列,若 a ...
- [BZOJ4993||4990] [Usaco2017 Feb]Why Did the Cow Cross the Road II(DP + 线段树)
传送门 f[i][j]表示当前第i个,且最后一个位置连接到j 第一维可以省去,能连边的点可以预处理出来,dp可以用线段树优化 #include <cstdio> #include < ...
- [Usaco2017 Feb]Why Did the Cow Cross the Road II (Platinum)
Description Farmer John is continuing to ponder the issue of cows crossing the road through his farm ...
- [Usaco2017 Feb]Why Did the Cow Cross the Road II (Gold)
Description 上下有两个长度为n.位置对应的序列A.B, 其中数的范围均为1~n.若abs(A[i]-B[j])<= 4,则A[i]与B[j]间可以连一条边. 现要求在边与边不相交的情 ...
- 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
题面:4989: [Usaco2017 Feb]Why Did the Cow Cross the Road 连接 http://www.lydsy.com/JudgeOnline/problem.p ...
- [BZOJ4989][Usaco2017 Feb]Why Did the Cow Cross the Road 树状数组维护逆序对
4989: [Usaco2017 Feb]Why Did the Cow Cross the Road Time Limit: 10 Sec Memory Limit: 256 MBSubmit: ...
随机推荐
- 不用JS,教你只用纯HTML做出几个实用网页效果
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://blog.bitsrc.io/pure-html-widgets-for-your- ...
- 从原理到场景 系统讲解 PHP 缓存技术
第1章课程介绍 此为PHP相关缓存技术的课堂,有哪些主流的缓存技术可以被使用? 第1章 课程介绍 1-1课程介绍1-2布置缓存的目的1-3合理使用缓存1-4哪些环节适合用缓存 第2章 文件类缓存 2- ...
- SpringCloud之Turbine
[前面的话]书接上文,本文的某些知识依赖我的上一篇SpringCLoud的文章:SpringCloud之Feign,如果没有看过可以先移步去看一下.前文提到了hystrix的应用,以及hystrix的 ...
- python的pywinrm模块远程连接windows执行dos命令
----A机器远程连接B---- 在A机器上安装模块: pip install pywinrm 在B机器上配置winrm服务的相关配置,使其支持远程控制: (winrm服务是windows 一种方便远 ...
- tomcat 报错出现 jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
这是你导入的jar的问题 一般情况下是导入的包tomcat已经存在 也就是说 不需要你再次导入 所以你现在要做的是删除你所导的包 解决方案:删除你的web项目导入的这两个jar文件 jsp-api.j ...
- 将Jexus+mono和网站一起通过Dockerfile打包到docker镜像
上次使用别人打包好的docker镜像,往里边加入文件,最终asp.net的docker容器化运行. 这次决定直接全新打包一个jexus+asp.net网站的docker包. 进入root目录,并在ro ...
- Spring boot 梳理 - @SpringBootConfiguration
@SpringBootConfiguration继承自@Configuration,二者功能也一致,标注当前类是配置类, 并会将当前类内声明的一个或多个以@Bean注解标记的方法的实例纳入到sprin ...
- openssl req(生成证书请求和自建CA)(转)
openssl req(生成证书请求和自建CA) 伪命令req大致有3个功能:生成证书请求文件.验证证书请求文件和创建根CA.由于openssl req命令选项较多,所以先各举几个例子,再集中 ...
- linux查看系统的一些版本号指令
1.查看系统 [root@iZbp1eoiap1e1jb6pvo390Z ~]# lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch ...
- Java8新特性——lambda函数式编程
一.遍历循环 /** * @author jiaqing.xu@hand-china.com * @version 1.0 * @name * @description 循环遍历 * @date 20 ...