Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接:
https://codeforces.com/contest/1265/problem/B
题意:
You are given a permutation p=[p1,p2,…,pn] of integers from 1 to n. Let's call the number m (1≤m≤n) beautiful, if there exists two indices l,r (1≤l≤r≤n), such that the numbers [pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m.
For example, let p=[4,5,1,3,2,6]. In this case, the numbers 1,3,5,6 are beautiful and 2,4 are not. It is because:
if l=3 and r=3 we will have a permutation [1] for m=1;
if l=3 and r=5 we will have a permutation [1,3,2] for m=3;
if l=1 and r=5 we will have a permutation [4,5,1,3,2] for m=5;
if l=1 and r=6 we will have a permutation [4,5,1,3,2,6] for m=6;
it is impossible to take some l and r, such that [pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m for m=2 and for m=4.
You are given a permutation p=[p1,p2,…,pn]. For all m (1≤m≤n) determine if it is a beautiful number or not.
思路:
记录每个值的位置,从1开始让最小的区间包围1-i,如果区间长度正好等于i就说明是一个i的排列。
代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;
int p[MAXN];
int n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while(t--)
{
cin >> n;
int a;
for (int i = 1;i <= n;i++)
cin >> a, p[a] = i;
int l, r;
l = r = p[1];
cout << 1;
for (int i = 2;i <= n;i++)
{
l = min(l, p[i]);
r = max(r, p[i]);
if (r-l+1 == i)
cout << 1;
else
cout << 0;
}
cout << endl;
}
return 0;
}
Codeforces Round #604 (Div. 2) B. Beautiful Numbers的更多相关文章
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)
题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...
随机推荐
- 1.RabbitMQ工作模型与基本原理
1.了解 MQ 的本质和 RabbitMQ 的特性: 2.掌握 RabbitMQ 的 Java API 编程和 Spring 集成 RabbitMQ 1. MQ 了解 1.1. 消息队列简介 ...
- Nvidia Jetson TX2开发板学习历程(1)- 详细开箱、上电过程
考试周已经结束了,开发板也已经到了.希望借着这个假期能够好好的利用这块开发板学习Linux系统以及Tensorflow的相关知识. 我打算将学习历程通过博客的方式写出来,作为自己的笔记,也可以供以后拿 ...
- Luogu4240 毒瘤之神的考验 莫比乌斯反演、根号分治
传送门 首先有\(\varphi(ij) = \frac{\varphi(i) \varphi(j) \gcd(i,j)}{\varphi(\gcd(i,j))}\),把欧拉函数的定义式代入即可证明 ...
- JAVA MyBybatis分页
java: import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; impo ...
- flutter AnimationBuilder
class BuilderPage extends StatefulWidget { @override State<StatefulWidget> createState() { // ...
- OO第4次博客作业
OO第4次博客作业 一.第4单元设计 第四单元主要围绕UML图的结构进行JAVA代码编写,对JAVA的层次结构进行更多的认识.个人认为编程操作在实质上与上一章的PathContainer有许多的相同之 ...
- 敏感词检测、屏蔽设计(iOS & Android)
敏感词检测 服务器端最常使用的算法是DFA算法.如果服务器端使用java实现常规的DFA算法,假若... 源码:https://github.com/qiyer/DFA_Cplusplus
- JQ分页的使用
<script src="../js/pageMe.js"></script> <script src="../js/comjq.js&qu ...
- mysql 的使用
1. 安装 https://dev.mysql.com/downloads/mysql/ 2. 配置 $ vim ~/.bash_profile $ export PATH=$PATH:/usr/lo ...
- SAP 2019 TechEd Key Note解读:云时代下SAP从业人员如何做二次开发?
刚刚过去的在巴塞罗那举行的2019 SAP TechEd,SAP照例向全球广大的SAP生态圈从业者们传达了一些重要的信息,其中一条为:Building Extensions for the Intel ...