luogu P2757 [国家集训队]等差子序列

题目链接

luogu P2757 [国家集训队]等差子序列

题解

线段树好题
我选择暴力

代码

// luogu-judger-enable-o2
#include<cstdio> 
inline int read() { 
    int x = 0,f = 1; 
    char c = getchar(); 
    while(c < '0' || c > '9')c = getchar(); 
    while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
    return x * f; 
} 
const int maxn = 10007; 
int a[maxn],b[maxn]; 
int main() { 
    int t = read(); 
    int n; 
    while(t --) {
        n = read(); bool flag = false;  
        for(int i = 1;i <= n;++ i) a[i] = read(),b[a[i]] = i; 
        for(int i = 1;i <= n;++ i) { 
            for(int j = 1;j <= n;++ j) { 
                int k = a[i]; 
                if(k + j + j <= n) if(b[k + j] > i && b[k + j + j] > b[k + j]) {flag = true;break;} 
                if(k - j - j > 0)  if(b[k - j] > i && b[k - j - j] > b[k - j]) {flag = true;break;} 
            } 
            if(flag) break; 
        } 
        if(flag) puts("Y"); 
        else puts("N"); 
        for(int i = 1;i <= n;++ i) b[i] = 0; 
    } 
    return 0; 
} 
posted @ 2018-08-12 21:59  zzzzx  阅读(192)  评论(0编辑  收藏  举报