B. The Forbidden Permutation

一定要注意题目中说的是对于all i满足才算不好的,我们做的时候只要破坏一个i这个a就不算好的了,被这一点坑了,没注意到all。

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int p[N], a[N]; void run()
{
memset(p, 0, sizeof p);
int n, m, d; scanf("%d%d%d", &n, &m, &d);
for(int i = 1; i <= n; ++ i)
{
int x; scanf("%d", &x);
p[x] = i;
}
for(int i = 1; i <= m; ++ i) scanf("%d", &a[i]);
int ans = 1e9;
for(int i = 1; i + 1 <= m; ++ i)
{
if(p[a[i + 1]] < p[a[i]] || p[a[i + 1]] > p[a[i]] + d)
{
cout << 0 << endl;
return;
}
if(p[a[i + 1]] > p[a[i]]) ans = min(ans, p[a[i + 1]] - p[a[i]]);
if(p[a[i + 1]] <= p[a[i]] + d)
if(d + 2 <= n) ans = min(ans, p[a[i]] + d + 1 - p[a[i + 1]]);
}
printf("%d\n", ans);
} int main()
{
// freopen("1.in", "r", stdin);
int t;cin >> t;
while(t --) run();
return 0;
}

Codeforces Round 848 (Div. 2)C的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. RabbitMQ 多消费者 使用单信道和多信道区别

    RabbitMQ 多个消费者共用一个信道实例 与 每个消费者使用不同的信道实例 区别: 1. 多个消费者共用一个信道实例:这种方式下,多个消费者共享同一个信道实例来进行消息的消费. 优点:这样可以减少 ...

  2. 园子的商业化努力:欢迎参加DataFun联合行行AI举办的数据智能创新与实践人工智能大会

    大家好,今年是园子商业化生死攸关的一年,正在艰难而努力地向前推进,今天在首页发布一篇大会推广博文,望谅解. DataFun联合行行AI举办第四届"数据智能创新与实践人工智能大会", ...

  3. 【Shell】数组

    数组 bash 只支持一维数组. 数组下标从 0 开始,下标可以是整数或算术表达式,其值应大于或等于 0. 创建数组 # 创建数组的不同方式 nums=([2]=2 [0]=0 [1]=1) colo ...

  4. NOIP模拟测试A2

    好像是去年 8 月 1 日的模拟赛,主题采自南昌起义. 背景 A. 南 一道可爱的期望 DP. 一般来说,期望 DP 都是逆推,从最终状态往前推,这题也不例外. 这道题难度主要在于,第 \(k\) 次 ...

  5. 分布式数据库oceanBase部署

    分布式数据库oceanBase部署 相关链接 文档中心 视频中心 软件下载 OceanBase数据库基本操作 OceanBase简介 SQL执行计划 基本概念 为了更好地管理 OceanBase 数据 ...

  6. React: 路由重定向

    解决方案 参考链接 https://v5.reactrouter.com/web/example/route-config

  7. html中的一些常用标签与标签属性

    label for属性 定义和用法 for 属性规定 label 与哪个表单元素绑定. <span> <label for="username">用户账号& ...

  8. .NET Core WebAPI中使用Swagger(完整教程)

    一.Swagger简介 1.1-什么是Swagger? Swagger是一个规范且完整的框架,用于生成.描述.调试和可视化Restfull风格的Web服务. Swagger的目标是对Rest API定 ...

  9. SpringCloud-Hystrix服务熔断与降级工作原理&源码

    先附上Hystrix源码图 在微服务架构中,根据业务来拆分成一个个的服务,服务与服务之间可以相互调用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign来调用 ...

  10. 基于 SharpPcap 开发的简易嗅探器

    Sniffer Based on SharpPcap A packet capture coursework based on sharpcap development 一个基于 SharpPcap ...