链接:

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的更多相关文章

  1. Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)

    题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...

  2. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  3. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  4. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  5. 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 ...

  6. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  7. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  8. Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...

  9. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...

随机推荐

  1. [hdu 1062] Text Reverse | STL-stack

    原题 题目大意: t组数据,每组为一行,遇到空格时讲前面的单词反转输出. 题解: 显然的栈题,遇到空格时将当前栈输出清空即可 #include<cstdio> #include<st ...

  2. watchdog监控文件变化使用总结——转载

    原文链接地址:https://blog.csdn.net/xufive/article/details/93847372 概述 首先声明,本文讨论的 watchdog,不是单片机里的 watchdog ...

  3. Linux06 文件的打包和压缩(gzip/gunzip、tar、bzip2)

    一.gzip/gunzip 这是用于压缩和解压单个文件的工具,且使用方法比较简单 gzip  文件名 gunzip  文件名 二.tar(用的比较多) 不仅可以用于打包文件,还可以将整个目录中的全部文 ...

  4. python 之 Django框架(APP和ORM的使用)

    12.3 APP 12.31 创建APP 一个Django项目可以分为很多个APP,用来隔离不同功能模块的代码 用命令行创建一个APP: python3 manage.py startapp app0 ...

  5. xorm -Alias,Asc,Desc方法实例

    Alias(string)给Table设定一个别名 package main import ( "fmt" _ "github.com/go-sql-driver/mys ...

  6. 从create-react-app开始,构建项目架构

    1.生成项目 命令行执行:create-react-app  myapp,生成如下结构: 2.安装sass依赖,让你在项目中可以使用scss模块化,index.module.scss: npm i n ...

  7. python3与Excel的完美结合

    https://segmentfault.com/a/1190000016256490 Excel 是 Windows 环境下流行的.强大的电子表格应用.openpyxl 模块让 Python 程序能 ...

  8. [洛谷P5431]【模板】乘法逆元2

    题目大意:给定$n(n\leqslant5\times10^6)$个正整数$a_i$,和$k$.求:$$\sum_{i=1}^n\dfrac{k^i}{a_i}\pmod p$$题解:$$令P=\pr ...

  9. Python爬虫快速上手教程

    1 这个是什么        整理Python中requests常用的API 2 代码 from bs4 import BeautifulSoup import requests import re ...

  10. Java JDK1.8源码学习之路 1 Object

    写在最前 对于一个合格的后端程序员来说,现行的流行框架早已经能胜任基本的企业开发,Springboot 任何的框架都把重复的工作更佳简单/优化的解决掉,但是完全陷入在这样的温水里面, 好比温水煮青蛙, ...