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 ...
随机推荐
- 普通平衡树 lg3369
在多次学习splay后,我终于理解并码出了整份代码 参考了https://tiger0132.blog.luogu.org/slay-notes的博客 具体实现原理在上面这篇博客和百度中可以查到,接下 ...
- WPF:MVVM模式下ViewModel调用View
两种基本方法: 消息通知和参数传递 一.消息通知 利用View里的IsEnable属性 原理是这样的: 1.UI中的IsEnabled绑定VM中的属性 2.UI的后台代码中,注册IsEnableCha ...
- python解压压缩包的几种方式
这里讨论使用Python解压如下五种压缩文件: .gz .tar .tgz .zip .rar 简介 gz: 即gzip,通常只能压缩一个文件.与tar结合起来就可以实现先打包,再压缩. tar: ...
- jenkins集成robot
一.jenkins集成robot的非gui的运行命令 pybot 配置文件 用例地址 或者robot 配置文件 用例地址 二.展示robot 运行结果图表 1.在系统配置中增加Rob ...
- Linux线程间同步的几种方式
信号量 信号量强调的是线程(或进程)间的同步:"信号量用在多线程多任务同步的,一个线程完成了某一个动作就通过信号量告诉别的线程,别的线程再进行某些动作(大家都在sem_wait的时候,就阻塞 ...
- AcWing 793. 高精度乘法
https://www.acwing.com/problem/content/795/ #include<bits/stdc++.h> using namespace std; //A*b ...
- 等差数列Arithmetic Progressions题解(USACO1.4)
Arithmetic Progressions USACO1.4 An arithmetic progression is a sequence of the form a, a+b, a+2b, . ...
- Python的DataFrame遍历_转CSDN_J小白Y
转CSDN_J小白Y:https://blog.csdn.net/Jarry_cm/article/details/99683788 1.DataFrame.iterrows() 返回{索引,Seri ...
- SpringBoot整合Mybatis案例
SpringBoot整合Mybatis案例 2019/7/15以实习生身份入职公司前端做Angular ,但是感觉前途迷茫,于是乎学习一下Java的框架——SpringBooot. 参照大神博客:ht ...
- 利用Ajax实现数据的同步传输,从mysql中提取数据,通过echarts可视化
如何将mysql数据库中的方式通过echarts可视化呢,以下面这个简单的例子向大家进行演示: 步骤一:mysql的创表和插入数据,当然这些数据也可以是你通过爬虫抓取的. 步骤二: 创 ...