Codeforces Round 848 (Div. 2)C
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的更多相关文章
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- List去除重复数据的五种方式
来自:CSDN,作者:多纤果冻 链接:https://blog.csdn.net/qq_37939251/article/details/90713643 以下介绍五种-不同的方法去除 Java 中A ...
- 手写raft(一) 实现leader选举
1. 一致性算法介绍 1.1 一致性同步与Paxos算法 对可靠性有很高要求的系统,通常都会额外部署1至多个机器为备用副本组成主备集群,避免出现单点故障. 有状态的系统需要主节点与备用副本间以某种方式 ...
- iframe与主窗口通信
1. 引言 <iframe> 元素是 HTML 中的一个标签,用于在当前页面中嵌入另一个页面 使用 <iframe> 可以实现以下功能: 嵌入其他网页:可以将其他网页嵌入到当前 ...
- pc 移动端 双端切换
实现一个项目匹配多个端,使用vue.config自带的page 实现多个页面切换.官网介绍:https://cli.vuejs.org/zh/config/#pages 在创建的vue项目中找到 vu ...
- CentOS7挂载NTFS格式的硬盘
前言 一些NTFS格式的移动硬盘或U盘插在服务器上可能不会自动挂载,本文为手动挂载的步骤. 步骤 安装相关程序: yum install -y ntfs-3g 使用一些命令查看需要挂载的分区 # 查看 ...
- TensorRT 模型加密杂谈
在大多数项目交付场景中,经常需要对部署模型进行加密.模型加密一方面可以防止泄密,一方面可以便于模型跟踪管理,防止混淆. 由于博主使用的部署模型多为TensorRT格式,这里以TensorRT模型为例, ...
- Unity的AssetPostprocessor之Model:深入解析与实用案例 1
Unity AssetPostprocessor模型相关函数详解 在Unity中,AssetPostprocessor是一个非常有用的工具,它可以在导入资源时自动执行一些操作.在本文中,我们将重点介绍 ...
- 【io_uring】简介和使用
文章目录 简介 使用 系统调用 liburing 样例 代码流程 编译 参考资料 简介 io_uring 是 Linux 在 5.1 版本引入的一套新的异步 IO 实现.相比 Linux 在 2.6 ...
- JWT(Json Wen Token)原理剖析
JWT(即json web token),大家先看下面这张图 大家可以观察到,jwt String就是生成后的jwt字符集,其中有两个 "."(注意:jwt校验会对".& ...
- CentOS 8 无痕升级到 Rocky Linux
CentOS 8 无痕升级到 Rocky Linux 1.升级当前系统 dnf upgrade -y 2.重启当前系统: reboot 3.下载脚本: CentOS 8 到 Rocky Linux 8 ...