要点

  • 没想到的一点是,对于堆里的某牌,最好情况是它出来时后边都准备就绪了,答案是\(p[i] + (n - i + 1)\),所有的这个取最大的即可
  • 一发结束的情况先特判一下
const int maxn = 2e5 + 5;
int n, pos, ans;
int a[maxn], b[maxn], In[maxn], p[maxn]; int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
rep(i, 1, n) {
cin >> a[i];
}
rep(i, 1, n) {//in pile
cin >> b[i];
if (b[i] == 1) pos = i;
}
if (pos) {//special
int flag = 1, k = 1;
rep(i, pos, n)//1 2 3......until the end
if (b[i] != k++) {
flag = 0; break;
}
if (flag) {
rep(i, 1, n)//in hand
In[a[i]] = 1;
int need = n - pos + 2;
rep(i, 1, pos - 1) {
if (!In[need]) {
flag = 0; break;
}
In[b[i]] = 1;
need++;
}
if (flag) {//一气呵成
cout << pos - 1 << endl;
exit(0);
}
}
} rep(i, 1, n)
p[b[i]] = i;
rep(i, 1, n)
ans = max(ans, p[i] + (n - i + 1));//all ready for those behind i
cout << ans << endl;
return 0;
}

Codeforces #564div2 C(模拟)的更多相关文章

  1. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  2. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  3. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  4. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  5. Codeforces 679B. Barnicle 模拟

    B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...

  6. CodeForces 382C【模拟】

    活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...

  7. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑...

  8. CodeForces 705C Thor (模拟+STL)

    题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...

  9. CodeForces 697B Barnicle 模拟

    强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...

随机推荐

  1. Android窗口系统第一篇---Window的类型与Z-Order确定

    Android的窗口系统是UI架构很重要的一部分,数据结构比较多,细节比较多.本篇文章主要介绍窗口相关数据结构和抽象概念理解,关于[窗口部分的博客]计划如下. 1.窗口Z-Order的管理 2.应用程 ...

  2. 搭建LoadRunner中的场景(四)控制器的全局设置

    选择“Tools”菜单-“Options”选项打开设置窗口 1.超时设置 2.运行时设置 3.运行时文件存储设置 4.路径翻译表 路径翻译表是一种映射,将控制器上的文件路径转换为远程主机上的文件路径. ...

  3. 最近火狐浏览器 总是“插件 adobe flash 已崩溃”

    原因和解决方案:在地址栏中输入:about:addons>在如下地方发现firefox已经在警告该插件的安全性了>选择“总不激活”

  4. 分布式锁的实现方式——ACID数据库、缓存或者是zk

    针对分布式锁的实现,目前比较常用的有以下几种方案: 基于数据库实现分布式锁 基于缓存(redis,memcached,tair)实现分布式锁 基于Zookeeper实现分布式锁 在分析这几种实现方案之 ...

  5. smack

    XMPP/Smack/Openfire javax.net.ssl.SSLException: Received fatal alert: internal_error 解决: 1.在链接openfi ...

  6. Eclipse IDE 主题颜色

    已安装好的 Eclipse IDE help > install new software 打开窗口 输入地址 http://eclipse-color-theme.github.io/upda ...

  7. MongoDB4.0.0的安装配置—windows

    一.背景 由于要学习MongoDB,所以就下载了最新的MongoDB 的Community Server版的4.0.0版本.可能是新的版本的缘故,在安装配置上与MongoDB3有许多不同,而且在3中的 ...

  8. Java Security(JCE基本概念)

    Java Security网络环境中的安全隐患计算机安全OSI参考结构模型五类安全服务八类安全机制网络环境中的安全隐患1. 存储问题: 移动存储设备存储数据没有加密存在的安全隐患 2. 通信问题: 用 ...

  9. @SpringBootApplication注解分析

    首先我们分析的就是入口类Application的启动注解@SpringBootApplication,进入源码: @Target(ElementType.TYPE) @Retention(Retent ...

  10. linux 命令2

    who who am i ssh scott@192.168.1.105 ps aux | grep pts/8 pwd // where are you? Page 205 mkdir -p dir ...