[CF1311B] WeirdSort

Solution
按照 \(p[i]\) 进行分段,如果某个 \(k\) 不存在 \(p[i]=k\),那么就把 \(i,i+1\) 分割开
处理出每一段的左端点和右端点
进而处理出每段的最小值和最大值
如果存在第 \(i\) 段的最大值大于第 \(i+1\) 段的最小值,就输出 NO
#include <bits/stdc++.h>
using namespace std;
#define reset(x) memset(x,0,sizeof x)
const int N = 1005;
int T,n,m,a[N],p[N],b[N],l[N],r[N],mx[N],mn[N];
signed main() {
cin>>T;
while(T--) {
reset(a); reset(p); reset(b);
reset(r); reset(l);
reset(mx); reset(mn);
cin>>n>>m;
for(int i=1;i<=n;i++) {
cin>>a[i];
}
for(int i=1;i<=m;i++) {
cin>>p[i];
b[p[i]]=1;
}
int ind=1;
l[1]=1;
for(int i=1;i<=n;i++) {
if(b[i]==0) r[ind]=i, l[++ind]=i+1;
}
--ind;
for(int i=1;i<=ind;i++) {
mx[i]=0; mn[i]=1e9;
for(int j=l[i];j<=r[i];j++) {
mx[i]=max(mx[i],a[j]);
mn[i]=min(mn[i],a[j]);
}
}
int flag=1;
for(int i=1;i<ind;i++) {
if(mx[i]>mn[i+1]) flag=0;
}
if(flag) puts("YES");
else puts("NO");
}
}
[CF1311B] WeirdSort的更多相关文章
- Codeforces Round #624 (Div. 3) B. WeirdSort(排序)
output standard output You are given an array aa of length nn . You are also given a set of distinct ...
- Codeforce1311B. WeirdSort (冒泡排序)
You are given an array a of length n. You are also given a set of distinct positions p1,p2,-,pm, whe ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #624 (Div. 3)(题解)
A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...
随机推荐
- maven远程部署到tomcat8服务器
maven远程部署到tomcat8服务器 环境准备 linux服务器一台 服务器安装JDK 服务器安装Tomcat 服务器Tomcat8配置 添加Tomcat权限 配置文件路径: tomcat/con ...
- Spring IoC 容器和 bean 对象
程序的耦合性: 耦合性(Coupling),又叫耦合度,是对模块间关联程度的度量.耦合的强弱取决于模块间接口的复杂性.调用模块的方式以及通过界面传送数据的多少.模块间的耦合度是指模块之间的依赖关系,包 ...
- LeetCode 677. Map Sum Pairs 键值映射(C++/Java)
题目: Implement a MapSum class with insert, and sum methods. For the method insert, you'll be given a ...
- ROS机器人之动作(一)
前面我们探讨了ros的两种通信方式,话题和服务,服务机制常用于同步的请求/响应交互方式. 话题则是单工通信,尤其是接收方有多时(比如传感器数据流),然而,当需要完成的任务比较复杂时, 服务和话题都不是 ...
- LUAMD5加密
md5里的方法: C:\Windows\System32>lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > require( ...
- learn about sqlserver partitition and partition table --- add or remove table partitions addition more
Yes . In the previous. chapter , we see how to generate "partition function" "parttit ...
- input . type=number.使用后问题点
所有主浏览器都支持type属性,但是,并非所有主流浏览器都支持所有不同的 input 类型. 以下 input 类型是 HTML5 中的新类型:color.date.datetime.datetime ...
- Yandex Big Data Essentials Week1 Unix Command Line Interface File System exploration
File System Function In computing, a file system or filesystem is used to control how data is stored ...
- [源码分析] 从源码入手看 Flink Watermark 之传播过程
[源码分析] 从源码入手看 Flink Watermark 之传播过程 0x00 摘要 本文将通过源码分析,带领大家熟悉Flink Watermark 之传播过程,顺便也可以对Flink整体逻辑有一个 ...
- docker介绍 架构 安装
Docker是什么? docker是一个开源的软件部署解决方案: docker也是轻量级的应用容器框架: docker可以打包.发布.运行任何的应用. Docker 是一个开源的应用容器引擎,基于 G ...