• 题意:给你一长度为\(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. 【Flutter】容器类组件之变换

    前言 Transform可以在其子组件绘制时对其应用一些矩阵变换来实现一些特效. 接口描述 const Transform({ Key key, @required this.transform, t ...

  2. LeetCode 二分查找模板 I

    模板 #1: int binarySearch(vector<int>& nums, int target){ if(nums.size() == 0) return -1; in ...

  3. 7.prometheus之查询API

    一.格式概述 二.表达式查询 2.1 Instant queries(即时查询) 2.2 范围查询 三.查询元数据 3.1 通过标签匹配器找到度量指标列表 3.2 获取标签名 3.3 查询标签值 四. ...

  4. .NET 5网络操作的改进

    随着.net 5在11月的发布,现在是谈论网络栈中许多改进的好时机.这包括对HTTP.套接字.与网络相关的安全性和其他网络通信的改进.在这篇文章中,我将重点介绍一些版本中更有影响力和更有趣的变化. H ...

  5. 【ASM】asm中添加 diskgroup

    环境:rhel5 Oracle10g rac 背景:在esxi中添加了一个20g的共享磁盘准备存放归档日志用 一.准备环境 1.添加共享磁盘并且格式化 #fdisk -l查看磁盘已经添加完成 #fdi ...

  6. CSRF - Pikachu

    概述: Cross-site request forgery 简称为"CSRF"(跨站请求伪造),在CSRF的攻击场景中攻击者会伪造一个请求(这个请求一般是一个链接),然后欺骗目标 ...

  7. Java程序入门

    编写Java源程序 在d:\day01 目录下新建文本文件,完整的文件名修改为HelloWorld.java ,其中文件名为HelloWorld ,后缀名必须为.java . 用记事本打开 在文件中键 ...

  8. MAX232数据方向

    在调试一个新板子的时候,串口调试从来都是放在前面的,而由于是一个新板子,电路图也是新的,因此有时候不知道串口线结对了没有,这个时候可能会对照PCB和原理图去看一下,但有时候看的人会很迷糊,因为不同的人 ...

  9. linux设备文件

    一.前言 在调用了alloc_chrdev_region函数或register_chrdev_region函数之后可以在/proc/devices中看到该设备的主设备号,比如我注册的hello模块的主 ...

  10. 变量隐藏Accidental Variable Shadowing

    6.5 - Variable shadowing (name hiding) | Learn C++ https://www.learncpp.com/cpp-tutorial/variable-sh ...