[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: ...
随机推荐
- springboot postman 对象里传时间格式问题
主要问题是系列化的问题,在定义时间变量处使用如下的注解即可.导包注意了······ 如果springmvc使用的是com.fasterxml.jackson 的jar包则直接使用一下注解即可 impo ...
- 关于mock
关于mock 一.什么是mock? 通俗来讲,在开发和测试过程中,由于环境不稳定或者协同开发的同事未完成等情况下,有些数据不容易构造或者不容易获取,就创建一个虚拟的对象或者数据样本,用来辅助开发或者测 ...
- Qt无边框窗体-模拟模态窗体抖动效果
目录 一.概述 二.效果展示 三.功能实现 四.相关文章 原文链接:Qt无边框窗体-模拟模态窗体抖动效果 一.概述 用Qt开发windows客户端界面确实是一大利器,兼顾性能的同时,速度相对来说也不错 ...
- 过渡 - transition
过渡 - transition 是变形transfrom其中一种效果,定义为一种状态过渡到另一种状态的过程,今天学习到css3动画,特此记录下过渡的使用和一些效果. 实例1: <div clas ...
- mysql-connector-java-5.-bin.jar 下载方法
访问https://downloads.mysql.com/archives/c-j/,选择相应版本,如图 加油zip即可得到
- 【Django】一对多表结构
1.创建project数据库表 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.co ...
- Android adb shell am 命令学习(1)
am:activity manager 启动Activity,打开或关闭进程,发送广播等操作 为什么学习: 主要应用部分,后台启动对应的package的Activity adb shell am st ...
- Spring boot 梳理 -@SpringBootApplication、@EnableAutoConfiguration与(@EnableWebMVC、WebMvcConfigurationSupport,WebMvcConfigurer和WebMvcConfigurationAdapter)
@EnableWebMvc=继承DelegatingWebMvcConfiguration=继承WebMvcConfigurationSupport 直接看源码,@EnableWebMvc实际上引入一 ...
- Redis 的主从同步(复制)
Redis 的主从同步(复制) Redis 的主从同步(复制) 什么是主从同步(复制) 假设有两个 redis 实例 ⇒ A 和 B B 实例的内容与 A 实例的内容保持同步 那么称 A 实例是主数据 ...
- 正睿OI DAY3 杂题选讲
正睿OI DAY3 杂题选讲 CodeChef MSTONES n个点,可以构造7条直线使得每个点都在直线上,找到一条直线使得上面的点最多 随机化算法,check到答案的概率为\(1/49\) \(n ...