• 题意:给你一长度为\(n\)的数组,有一长度为\(k\ (1\le k \le n)\)的区间不断从左往右扫过这个数组,总共扫\(n\)次,每次扫的区间长度\(k=i\),在扫的过程中,每次取当前区间内的最小值,存到v中,问每次扫完后v中的数是否能构成一个序列.
  • 题解:我们首先特判区间长度\(1\)和\(n\)的情况,这很简单,然后我们从\([n-1,2]\)枚举区间长度(也就对应着我们枚举每次选的数\(1,2...n\)),不难发现,当区间长度为\(n-1\)时,我们要选两个数,且这两个数只能是\(1,2\),且\(1\)必须在数组的第一个位置或者最后一个位置,假如它在\([2,n-1]\)中出现的话,我们当前的区间会向右移动一个单位,所以必然会取两次\(1\),当然,这同时也要求\(1\)在数组中只能出现一次,同时\(2\)必须要在数组中存在,以此向后递推其他的情况,判断我们要选的数是不是在区间的边界即可.
  • 代码:
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
#define rep(a,b,c) for(int a=b;a<=c;++a)
#define per(a,b,c) for(int a=b;a>=c;--a)
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;} int t;
int n;
int a[N];
int ans[N];
int cnt[N]; int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
cin>>n;
rep(i,1,n) cnt[i]=0,ans[i]=0;
rep(i,1,n) cin>>a[i],cnt[a[i]]++; if(cnt[1]>=1) ans[n]=1; ans[1]=1;
rep(i,1,n){
if(cnt[i]!=1){
ans[1]=0;
break;
}
} int l=1,r=n; //因为我们每次选完后l或r的位置就被1...i-1的数占掉了,所以要移动. rep(i,1,n-1){
if(!cnt[i] || cnt[i]>1) break;
if(a[l]==i && cnt[i+1]){
l++;
ans[n-i]=1;
}
else if(a[r]==i && cnt[i+1]){
r--;
ans[n-i]=1;
}
else break;
} rep(i,1,n) cout<<ans[i];
cout<<'\n'; } return 0;
}

Codeforces Global Round 12 D. Rating Compression (思维,双指针)的更多相关文章

  1. Codeforces Global Round 1D(DP,思维)

    #include<bits/stdc++.h>using namespace std;int dp[1000007][7][7];int cnt[1000007];int main(){  ...

  2. Codeforces Global Round 6 - D. Decreasing Debts(思维)

    题意:有$n$个人,$m$个债务关系,$u_{i}$,$v_{i}$,$d_{i}$表示第$u_{i}个人$欠第$v_{i}$个人$d_{i}$块钱,现在你需要简化债务关系,使得债务总额最小.比如,$ ...

  3. Codeforces Global Round 5E(构造,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int main(){ ios::sync_w ...

  4. Codeforces Global Round 4E(字符串,思维)

    #include<bits/stdc++.h>using namespace std;string s,a,b;int main(){ cin>>s; int n=s.size ...

  5. Codeforces Global Round 9 C. Element Extermination (思维,栈)

    题意:有一个长度\(n\)的序列,如果\(a_{i}<a_{i+1}\),那么可以选择删除\(a_{i}\)或者\(a_{i+1}\),再继续操作,问是否能够将序列删到只剩一个元素. 题解:感觉 ...

  6. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  7. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  8. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

  9. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

随机推荐

  1. 有关Servlet的面试题

    CGI(Common Gateway Interface),通用网管接口 通用网管接口,简称CGI,是一种根据请求信息动态产生回应内容的技术.通过CGI,web服务器可以根据请求的不同,启动不同的外部 ...

  2. MySQL where 条件字句查询

    where 条件字句 搜索条件可由一个或多个逻辑表达式组成 , 结果一般为布尔值 逻辑运算符 运算符 语法 描述 and && a and b a && b 逻辑与 两 ...

  3. ABAP program lines are wider than the internal table

    错误详细描述: An exception occurred that is explained in detail below.The exception, which is assigned to ...

  4. C++ STL 栈和队列

    栈和队列 头文件 #include<queue> // 队列 #include<stack> //栈 定义方式 //参数就是数据类型 stack<int> s; q ...

  5. mastercam2018安装教程

    安装前先关闭杀毒软件和360卫士,注意安装路径不能有中文,安装包路径也不要有中文. [安装环境]:Win7/Win8/Win10 1.选中[Mastercam2018]压缩包,鼠标右击选择[解压到Ma ...

  6. ElasticSearch Python 基本操作

    创建索引 from elasticsearch import Elasticsearch es = Elasticsearch('192.168.149.96:9200') mappings = { ...

  7. Ubuntu对接GlusterFS

    存储节点部署示例环境,仅供参考 主机名 IP 系统 gfs01 10.10.10.13 Ubuntu 16.04.3 LTS gfs02 10.10.10.14 Ubuntu 16.04.3 LTS ...

  8. jQuery 勾选启用输入框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. IDEA_2019.1版本中Protobuf的使用

    一.Protobuf是什么 Protobuf 是 Google 发布的开源项目,全称 Google Protocol(/'prəʊtəkɒl/,协议,草案) Buffers,是一种轻便高效的结构化数据 ...

  10. ChannelNets: 省力又讨好的channel-wise卷积,在channel维度进行卷积滑动 | NeurIPS 2018

    Channel-wise卷积在channel维度上进行滑动,巧妙地解决卷积操作中输入输出的复杂全连接特性,但又不会像分组卷积那样死板,是个很不错的想法   来源:晓飞的算法工程笔记 公众号 论文: C ...