Codeforces Round #604 (Div. 2)

https://codeforces.com/contest/1265

这场的2E是1C的不带checkpoints的版本。

B - Beautiful Numbers

题意:给一个数组是一个[1,n]的permutation。对每个m∈[1,n]问[1,m]是否连续存在在这个数组中。

题解:

首先,[1,1]一定存在。

然后向指定方向扩展到2,若经过2以外的数,把2标记为不存在。

3已经被扩展,或3在区间左右?是:否。

所以每次就问新的数是不是在已有区间中或者左右,是则包含,否则扩展到有为止。

int pos[MAXN + 5];

void test_case() {
    int n;
    scanf("%d", &n);
    for(int i = 1, ai; i <= n; ++i) {
        scanf("%d", &ai);
        pos[ai] = i;
    }
    int l = n + 1, r = 0;
    for(int i = 1; i <= n; ++i) {
        l = min(l, pos[i]);
        r = max(r, pos[i]);
        putchar('0' + (r - l + 1 == i));
    }
    putchar('\n');
}

事实上判断一下区间的长度就可以了。

原文地址:https://www.cnblogs.com/KisekiPurin2019/p/11993944.html

时间: 2024-07-31 05:12:46

Codeforces Round #604 (Div. 2)的相关文章

Codeforces Round #604 (Div. 2) A. Beautiful String

链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa&

Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s1,s2,-,sn is beautiful if |si?si+1|=1 for all 1≤i≤n?1. Trans

Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved pi problems. Since

Codeforces Round #604 (Div. 2) 练习A,B题解

A题 链接 思路分析: 因为只需要做到相邻的不相同,利用三个不同的字母是肯定可以实现的, 所以直接先将所有的问号进行替换,比如比前一个大1,如果与后面的冲突,则再加一 代码(写的很烂): #include <bits/stdc++.h> using namespace std; int check( string a) { for (int i = 0; i < a.length(); ++i) { if (i==0) { if (a[i]==a[i+1]) { return 0; }

Codeforces Round #604 (Div. 2) D、E、F题解

Beautiful Sequence \[ Time Limit: 1000 ms\quad Memory Limit: 256 MB \] 首先我们可以考虑到 \(0\) 只能 和 \(1\) 放在一起.\(3\) 只能和 \(2\) 放在一起,那么我们想办法先把 \(0\) 和 \(3\) 凑出来,最后就剩下 \(1\) 和 \(2\) 了,我们只要把他们放在一起就可以了. 所以我们可以贪心考虑三个 \(string\),分别长成 \(0101...0101\).\(2323...2323\

Codeforces Round #604 (Div. 2)D(构造)

构造,枚举起点,如果一个序列成立,那么将它reverse依然成立,所以两个方向(从小到大或从大到小)没有区别,选定一个方向进行探测,直到探测不到以后回头,只要所给数据能成立,那么能探测进去就能探测出来,否则就不能构造. 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 int num[7]; 5 int sum; 6 int main(){ 7 ios::sync_with_std

Codeforces Round #604 (Div. 2)(A-E)

A. Beautiful String 题意:把'?'换成'a' or 'b' or 'c'使得相邻的两个字符不相同. 暴力枚举每个'?'前后. #include <bits/stdc++.h> using namespace std; const int MAXN=1e5+10; string s; int main(){ ios::sync_with_stdio(false); int T; cin>>T; while(T--){ cin>>s; bool ok=t

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿