https://www.luogu.org/problem/P2757
Title Description
Arrangement to a 1 to N {Ai}, asking whether there
1 \le p_1<p_2<p_3<p_4<p_5<…<p_{Len} \le N (Len \ge 3)1≤p1<p2<p3<p4<p5<…<pLen≤N(Len≥3)
Such AP_1, AP_2,, AP_3, \ cdots, ap_ Len} { A P . 1 , A P 2 , A P . 3 , ⋯ , A P L E n- is an arithmetic sequence.
Input Format
The first line of the input contains an integer T, it denotes the number of groups.
T then the set of data, each line of a first integer N, each arranged in a second line 1 to N, the number separated by a space between any two.
Output Format
For each test, if an arithmetic sequence, it outputs a line "Y", and otherwise outputs a row "N".
Sample input and output
2 3 1 3 2 3 3 2 1
N Y
Description / Tips
For 5% of data, N <= 100
For 30% of the data, N <= 1000
To 100% of the data, N <= 10000, T <= 7
Arithmetic sequence x, y, z, x and z are symmetric about the y by comparison bitset
The first to write bitset, a cancer too
#include<iostream> #include<cstdio> #define ri register int #define u int namespace opt { inline u in() { u x(0),f(1); char s(getchar()); while(s<'0'||s>'9') { if(s=='-') f=-1; s=getchar(); } while(s>='0'&&s<='9') { x=(x<<1)+(x<<3)+s-'0'; s=getchar(); } return x*f; } } using opt::in; #include<bitset> #include<algorithm> #define NN 10005 namespace mainstay { using std::bitset; typedef bitset<NN> bit; bit e1,e2,bas; u check(u x,const u &N) { if(x<=N/2) { bit _t1((bas>>(N-x))&(e1)); _t1.set(0); bit _t2((bas>>(N-x))&(e2>>(N-2*x+1))); _t2.set(0); if(_t1!=_t2) return 1; else return 0; } else { bit _t1(e1>>(x-1)); _t1.set(0); bit _t2((bas>>(x-1))&(e2>>(N-x))); _t2.set(0); if(_t1!=_t2) return 1; else return 0; } } inline void solve() { u T(in()); while(T--) { u N(in()),flg(0); e1.reset(),e2.reset(),bas.reset(); for(ri i(1); i<=N; ++i) bas.set(i); for(ri i(1); i<=N; ++i) { u _a(in()); e1.set(_a),e2.set(N+1-_a); if(check(_a,N)) flg=1; } if(flg) printf("Y\n"); else printf("N\n"); } } } int main() { //freopen("x.txt","r",stdin); std::ios::sync_with_stdio(false); mainstay::solve(); }