codeforces Beautiful Numbers
You are given a permutation p=[p1,p2,…,pn]p=[p1,p2,…,pn] of integers from 11 to nn . Let's call the number mm (1≤m≤n1≤m≤n ) beautiful, if there exists two indices l,rl,r (1≤l≤r≤n1≤l≤r≤n ), such that the numbers [pl,pl+1,…,pr][pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m1,2,…,m .
For example, let p=[4,5,1,3,2,6]p=[4,5,1,3,2,6] . In this case, the numbers 1,3,5,61,3,5,6 are beautiful and 2,42,4 are not. It is because:
- if l=3l=3 and r=3r=3 we will have a permutation [1][1] for m=1m=1 ;
- if l=3l=3 and r=5r=5 we will have a permutation [1,3,2][1,3,2] for m=3m=3 ;
- if l=1l=1 and r=5r=5 we will have a permutation [4,5,1,3,2][4,5,1,3,2] for m=5m=5 ;
- if l=1l=1 and r=6r=6 we will have a permutation [4,5,1,3,2,6][4,5,1,3,2,6] for m=6m=6 ;
- it is impossible to take some ll and rr , such that [pl,pl+1,…,pr][pl,pl+1,…,pr] is a permutation of numbers 1,2,…,m1,2,…,m for m=2m=2 and for m=4m=4 .
You are given a permutation p=[p1,p2,…,pn]p=[p1,p2,…,pn] . For all mm (1≤m≤n1≤m≤n ) determine if it is a beautiful number or not.
The first line contains the only integer tt (1≤t≤10001≤t≤1000 ) — the number of test cases in the input. The next lines contain the description of test cases.
The first line of a test case contains a number nn (1≤n≤2⋅1051≤n≤2⋅105 ) — the length of the given permutation pp . The next line contains nn integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n , all pipi are different) — the given permutation pp .
It is guaranteed, that the sum of nn from all test cases in the input doesn't exceed 2⋅1052⋅105 .
Print tt lines — the answers to test cases in the order they are given in the input.
The answer to a test case is the string of length nn , there the ii -th character is equal to 11 if ii is a beautiful number and is equal to 00 if ii is not a beautiful number.
3
6
4 5 1 3 2 6
5
5 3 1 2 4
4
1 4 3 2
101011
11111
1001
The first test case is described in the problem statement.
In the second test case all numbers from 11 to 55 are beautiful:
- if l=3l=3 and r=3r=3 we will have a permutation [1][1] for m=1m=1 ;
- if l=3l=3 and r=4r=4 we will have a permutation [1,2][1,2] for m=2m=2 ;
- if l=2l=2 and r=4r=4 we will have a permutation [3,1,2][3,1,2] for m=3m=3 ;
- if l=2l=2 and r=5r=5 we will have a permutation [3,1,2,4][3,1,2,4] for m=4m=4 ;
- if l=1l=1 and r=5r=5 we will have a permutation [5,3,1,2,4][5,3,1,2,4] for m=5m=5 .
解题思路:记录每个值的位置,从1开始让最小的区间包围1-i,如果区间长度正好等于i就说明是一个i的排列。
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef unsigned long long ll;
const int maxn = 1e6+;
int a[maxn];
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int k;
for(int i=;i<=n;i++){
cin>>k;
a[k]=i;
}
int l,r;
l=r=a[];
cout<<;
for(int i=;i<=n;i++){
l=min(l,a[i]);
r=max(r,a[i]);
if(r-l+==i){
cout<<;
}
else{
cout<<;
}
}
cout<<endl;
}
return ;
}
codeforces Beautiful Numbers的更多相关文章
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- 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 Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Beta Round #51 D. Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- CodeForces - 55D Beautiful numbers —— 数位DP
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...
随机推荐
- 【Python】字符串处理函数
- Python之旅第四天(列表、元祖、字典和习题)
第四天,感觉时间还是过得很快,今天内容确实有点多,关于list的方法实在是太多了,元组tuple感觉有点鸡肋,可能得到后面才知道他的作用吧,然后是字典,看了很多关于字典的介绍,但是这货到底是干啥用的一 ...
- C++中类成员变量的初始化问题
C++11之后允许对非静态成员变量进行初始化(in-class initialization),不过对于非fundamental(非基本数据)类型需要采用的是initializer_list来实现的 ...
- null值与非null只比较大小时,只会返回false
DateTime? time=null; DateTime now=DateTime.Now; null值与非null只比较大小时,只会返回false 无论是大于比较还是小于比较还是等于,都会返回fa ...
- Dockers的安装
添加yum源 #下载163的yum源到本地 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7 ...
- 洛谷P1327 数列排序
https://www.luogu.org/problem/P1327 #include<bits/stdc++.h> #define Ll long long using namespa ...
- 2.6.1 XML配置:创建XML文件
(1) 工程名右击---New--file -- newfile窗口中:filename中输入testng.xml testng.xml 文件中打开后,切换到source 标签中.进行编辑. 内容 ...
- [lua]紫猫lua教程-命令宝典-L1-01-10. 自定义函数
L1[function]01. 定义与调用函数 函数的定义 和概念 没什么可说的 lua的函数声明和调用是有先后顺序的 先声明后调用 函数就是变量的一种 所以可以自由的把函数在变量间相互赋值 不过注 ...
- 配置SSH使用密钥认证:实现免输入密码登陆
一.实际工作生产场景分析 张三是某公司员工,由于业务上的需求,需要经常使用SSH工具登陆服务器A的root账户进行操作,为避免重复进行密码验证身份.现采用张山的公钥发送给服务器A,免输入密码登陆到服务 ...
- alert警告框点击确定后自动提交表单
转载于 :https://zhidao.baidu.com/question/619375120140398412.html 在页面中有多个input type="text"的文 ...