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. Mysql基础4-数据查询

    一.DQL介绍 DQL全称:Data Query Language(数据查询语言),用来查询数据库中表的记录. 关键字:select 二.DQL语法 select 字段列表 from 表名列表 whe ...

  2. Python数据分析易错知识点归纳(四):Matplotlib

    四.matplotlib 基本特性 import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 50) y1 = ...

  3. PTA 21级数据结构与算法实验8—排序

    目录 7-1 统计工龄 7-2 寻找大富翁 7-3 点赞狂魔 7-4 插入排序还是归并排序 7-5 插入排序还是堆排序 7-6 逆序对 7-7 堆排序 7-8 石子合并 7-9 第k小 7-10 快速 ...

  4. windows CMD命令的一些使用方法及注意事项

    windows CMD命令的一些使用方法及注意事项 转载请著名出处:https://www.cnblogs.com/funnyzpc/p/17572397.html 一.执行路径或参数带中文.空格.特 ...

  5. 【游记】NOIP2022 预备赛游记

    Day -2 \(NOIP\) 就要来了,\(CSYZ\) 斥巨资给我们在 \(NOIP\) 正式考点举办了一场 \(NOIP\) 预备赛,真是太感动了~~ \(cy\) 说明天要颁奖,激动激动! D ...

  6. Linq开发技巧与业务逻辑校验

    Linq 是一种基于 .NET Framework 的编程语言,它的出现极大地提高了开发效率.Linq 提供了一种统一的查询语法,使得开发人员可以使用一种语言来查询不同类型的数据源,包括对象.集合.数 ...

  7. 解决win10/ubuntu端口占用问题

    win10解决方案 首先打开cmd命令行 命令行里输入 netstat -ano|findstr 被占用端口号 然后可以看到占用该端口号的pid 输入taskkill -f -pid pid号即可 u ...

  8. 推荐工具!使终端便于 DevOps 和 Kubernetes 使用

    如果你熟悉 DevOps 和 Kubernetes 的使用,就会知道命令行界面(CLI)对于管理任务有多么重要.好在现在市面上有一些工具可以让终端在这些环境中更容易使用.在本文中,我们将探讨可以让工作 ...

  9. 【故障公告】多年的故障老朋友又来了:数据库服务器 CPU 100%

    数据库服务器 CPU 100% 问题几乎每年都要来几次,从来都不事先打一声招呼,今年的第2次在我们正忙着会员救园的时候来了. 今天 13:35 首先收到我们自己的异常告警通知: Execution T ...

  10. 一次搞定:借助Hutool封装代码快速解决webservice调用烦恼

    前言 相信很多同行哪怕学了许多主流技术,但工作上依然免不了和传统企业打交道,而这样的企业往往还在用webservice做接口交互. 本文是作者近两年和医疗行业的厂家打交道研究出来的一点调用webser ...