给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N (Len>=3),
使得Ap1,Ap2,Ap3,…ApLen是一个等差序列。
标签:hint 辅助 因此 string https cstring bre col i++
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define ll long long 5 #define mod 1000000007 6 #define N 10005 7 using namespace std; 8 9 int n,a[N],pw[N]; 10 struct bit_node{ 11 int c[N]; 12 void clr(){ memset(c,0,sizeof(c)); } 13 void add(int x){ 14 int i; for (i=x; i<=n; i+=i&-i) c[i]=(c[i]+pw[i-x])%mod; 15 } 16 int getsum(int x){ 17 int i,t=0; for (i=x; i; i^=i&-i) t=((ll)c[i]*pw[x-i]+t)%mod; 18 return t; 19 } 20 int qry(int x,int y){ 21 int p=getsum(x-1),q=getsum(y); 22 return (q-(ll)p*pw[y-x+1]%mod+mod)%mod; 23 } 24 }bit1,bit2; 25 int main(){ 26 int cas,i; scanf("%d",&cas); 27 pw[0]=1; for (i=1; i<=10000; i++) pw[i]=(ll)pw[i-1]*12347%mod; 28 while (cas--){ 29 scanf("%d",&n); int x; 30 for (i=1; i<=n; i++) scanf("%d",&a[i]); 31 bit1.clr(); bit2.clr(); 32 for (i=1; i<=n; i++){ 33 x=min(a[i]-1,n-a[i]); 34 if (x && bit1.qry(a[i]-x,a[i]-1)!=bit2.qry(n-a[i]-x+1,n-a[i])) break; 35 bit1.add(a[i]); bit2.add(n-a[i]+1); 36 } 37 puts((i>n)?"N":"Y"); 38 } 39 }
bzoj 2124 等差子序列 树状数组维护hash+回文串
标签:hint 辅助 因此 string https cstring bre col i++
原文地址:https://www.cnblogs.com/fengzhiyuan/p/8847699.html