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. python:导入库、模块失败

    一般发生在程序开始部分: from pymodbus.client.sync import ModbusSerialClient from pymodbus.payload import Binary ...

  2. 你真正了解Spring的工作原理吗

     Spring   1.1 什么是Spring IOC 和DI ?   ① 控制反转(IOC):Spring容器使用了工厂模式为我们创建了所需要的对象,我们使用时不需要自己去创建,直接调用Spring ...

  3. 一个从文件中过滤指定字符串的python3脚本

    from tabulate import tabulate plugin = [ ... ] plugin_v1 = [ ... ] filepath = "E:\\PycharmProje ...

  4. 【技术实战】Vue技术实战【三】

    需求实战一 效果展示 代码展示 <template> <div style="display: flex;"> <div style="di ...

  5. fastposter v2.16.0 让海报开发更简单

    fastposter v2.16.0 让海报开发更简单 fastposter海报生成器是一款快速开发海报的工具.只需上传一张背景图,在对应的位置放上组件(文字.图片.二维.头像) 点击代码直接生成各种 ...

  6. Angular: 点击一次按钮,增加一个元素

    解决方案 思路 在组件的typesscript文件中,创建一个数组来存储每个按钮的信息 在模板中使用 *ngFor 指令来循环渲染按钮列表 在按钮事件的处理函数中,每次点击按钮时向按钮数组添加一个新的 ...

  7. pthon之字典的遍历

    对字典的操作稍有些陌生,在此记录一下. 字典的使用已{key:value}的形式存在,多个值以逗号分开. 字典的遍历共有三种方法,他们将返回类似列表的值,分别对应字典的键.值.键-值对.即keys() ...

  8. IE浏览器不支持TextDecoder()的问题

    IE浏览器不支持TextDecoder()方法,因此在进行Arrbuffer转string或中文时,出现未定义的错误.通过网上查找方法,可以通过引用第三方库进行解决. github地址:https:/ ...

  9. 震惊!强大的接口自动化测试框架2.0,unittest与pytest无缝穿插对接,可以像postman一样编写代码

    theme: fancy highlight: arta 项目介绍 接口自动化测试项目2.0 软件架构 本框架主要是基于 Python + unittest + ddt + HTMLTestRunne ...

  10. 个人GAN训练的性能迭代

    使用GAN进行生成图片 损失函数的迭代 DCGAN->Wasserstein GAN-> Wasserstein GAN + Gradient Penalty Discriminator训 ...