[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: ...
随机推荐
- Hive中的数据库(Database)和表(Table)
在前面的文章中,介绍了可以把Hive当成一个"数据库",它也具备传统数据库的数据单元,数据库(Database/Schema)和表(Table). 本文介绍一下Hive中的数据库( ...
- 安全性测试:OWASP ZAP 2.8 使用指南(二):ZAP基础操作
ZAP桌面应用 ZAP桌面应用由以下元素组成: 1. 菜单栏 – 提供多种自动化和手动工具的访问 2. 工具栏 – 提供快速访问最常用组件的用户接口 3. 树结构窗口 – 展示被测网站树结构和脚 ...
- PHP秒杀系统 高并发 高性能的极致挑战 下载
第1章 课程介绍 秒杀系统在各种网站和应用中经常会用到.本课程从基本的系统设计和基础功能开始教导大家用PHP来设计和实现秒杀系统,并且为海量并发提供更高级的技术方案和实现手段. 第2章 系统技术选型分 ...
- Linux 笔记 - 第八章 文档的打包与压缩
博客地址:http://www.moonxy.com 一.前言 在 Linux 系统中,文件的后缀名没有实际的意义,加或者不加都无所谓.但是为了便于区分,我们习惯在定义文件名时加一个后缀名,比如常见的 ...
- 【Python爬虫】第四课(查询照片拍摄地址)
首先,要能够查询到照片地址,查询的照片必须要开GPS拍,且上传时用原图…… 查询图片的exif信息,使用exifread包 import exifread img = exifread.process ...
- Mysql高手系列 - 第12篇:子查询详解
这是Mysql系列第12篇. 环境:mysql5.7.25,cmd命令中进行演示. 本章节非常重要. 子查询 出现在select语句中的select语句,称为子查询或内查询. 外部的select查询语 ...
- hadoop生态系列
1.hadoop高可用安装和原理详解 2.hadoop2.7+spark2.2+zookeeper3.4.简单安装 3.windows下通过idea连接hadoop和spark集群 4.hadoop2 ...
- 实例化Bean的几种方法
1.使用构造器实例化Bean. 当没有指定实例化方法时,Spring IoC容器能使用默认空构造器.构造器实例化包括默认空构造器和有参数构造器两种方式创建Bean. 2.使用构造器实例 ...
- thinkphp将上传的临时文件移动到指定目录
thinkphp将上传的临时文件移动到指定目录 新建common.php文件 <?phpuse think\facade\Env; /** 移动上传的临时文件 * * @img_dir stri ...
- Widget 中的 State 解析
StatefulWidget 应对有交互.需要动态变化视觉效果的场景 StatelessWidget 则用于处理静态的.无状态的视图展示 那么,StatelessWidget 是否有存在的必要?Sta ...