Codeforces Round #604 (Div. 2) B. Beautiful Numbers

【题目链接】B题链接

【题目类型】数学、模拟

【题目大意】给你一串序列,里面有1-n,n个数字。现在要求你求解是否判断m(1~n),是否存在一段连续子序列满足刚好有(1-m) m个数字,如果有答案序列m位置上的值就为1,没有就为0.

【解题思路】稍微概括一下,就是判断每个m和1的相对位置就能很好的判断是否存在子序列了。

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.moonl1ght.xyz
 *    created:
 */
//}/* .................................................................................................................................. */
const int maxn = 1e5+50;
char s[maxn];
int main(){
    int t; RD(t);
    stringstream ss;
    REP(T, t){
        int n; RD(n);
        int p[n], q[n];
        REP(i, n){
            RD(p[i]); q[--p[i]] = i;
        }
        int lo = n, hi = -1;
        REP(i, n){
            lo = min(lo, q[i]);
            hi = max(hi, q[i]);
            ss << (hi - lo == i);
        }
        ss << '\n';
    }
    cout <<ss.str();
}

你可能感兴趣的:(codeforces,codeforces,#604,B.Beautiful,Numbers,b)