• 题意:给你一长度为\(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. 代码审计 - BugkuCTF

    extract变量覆盖: 相关函数: extract()函数:从数组中将变量导入到当前的符号表.把数组键名作为变量名,数组的键值作为变量值.但是当变量中有同名的元素时会默认覆盖掉之前的变量值. tri ...

  2. F4IF_INT_TABLE_VALUE_REQUEST选择屏幕自定义F4帮助

    今天在用 F4IF_INT_TABLE_VALUE_REQUEST函数写选择屏幕的自定义帮助的时候,发现了个问题,那就是 F4IF_INT_TABLE_VALUE_REQUEST中参数value_ta ...

  3. Flask中的g到底是个什么鬼?

    g到底是个什么鬼? 在一次请求请求的周期,可以在g中设置值,在本次的请求周期中都可以读取或复制. 相当于是一次请求周期的全局变量. from flask import Flask,g app = Fl ...

  4. 备份和还原Windows DHCP服务器

    在本教程中,您将学习如何使用DHCP控制台和PowerShell备份和还原Windows DHCP服务器. 您是否曾经经历过DHCP服务器崩溃或故障?在设备开始重新启动之前,一切都会平静. 用户将抱怨 ...

  5. jvm源码解析java对象头

    认真学习过java的同学应该都知道,java对象由三个部分组成:对象头,实例数据,对齐填充,这三大部分扛起了java的大旗对象,实例数据其实就是我们对象中的数据,对齐填充是由于为了规则分配内存空间,j ...

  6. EMA algorithm: https://blog.csdn.net/m0_38106113/article/details/81542863

    EMA algorithm: https://blog.csdn.net/m0_38106113/article/details/81542863

  7. https://design-patterns.readthedocs.io/zh_CN/latest/index.html

    图说设计模式 - Graphic Design Patterns https://design-patterns.readthedocs.io/zh_CN/latest/index.html

  8. pickle — Python object serialization

    pickle - Python object serialization  消息队列

  9. Python学习【第2篇】:循环

    For循环 pass while 循环 pass 练习题: 1.使用while循环输入 1 2 3 4 5 6     8 9 10,不输出7 n = 1while n< 11: if n == ...

  10. 六:Spring Security 中使用 JWT

    Spring Security 中使用 JWT 1.无状态登录 1.1 什么是有状态? 1.2 什么是无状态 1.3 如何实现无状态 2.JWT 2.1 JWT数据格式 2.2 JWT交互流程 2.3 ...