Description
Design a data structure. Given a positive integer sequence a_0, A_1, ..., a_{n-1}, you need to support the following two actions:
1. MODIFY ID x: Modify A_{id} to X.2. QUERY x: Find the smallest integer p (0 <= p < n), making gcd (A_0, a_1, ..., a_p) * XOR (A_0, A_1, ..., a_p) = x. Where XOR (A_0, A_1,. ., a_p) represents A_0, A_1, ..., A_p xor, GCD represents greatest common divisor. Input
The first line of the input data contains a positive integer n.
The next line contains n positive integers a_0, a_1, ..., a_{n-1}.the next line contains a positive integer q, which indicates the number of queries. after the Q line, each line contains a query. Format as described in the topic. Output
For each query inquiry, output results in a separate row. If no such p exists, the output is no.
Block maintenance block within the GCD and each of the occurrence of the XOR prefix and position, modification can be violent refactoring the entire block, the query uses the nature of GCD, because the prefix GCD of the number of values is a number of levels, the prefix GCD unchanged block binary query, prefix GCD change block violence calculation, the total complexity of about O ( NSQRT (n) log (max (a_i)))
#include <cstdio>#include<cmath>#include<algorithm>Charbuf[5000007],*ptr=buf-1; template<classT>void_ (t&x) { intc=*++ptr; X=0; while(c< -) c=*++ptr; while(c> -) x=x*Ten+c- -, c=*++ptr;}int_c () {intc=*++ptr; while(c>'Z'|| c<'A') c=*++ptr; intR=C; while(c>='A'&&c<='Z') c=*++ptr; returnR;}BOOLdt[555];intn,q,a[100007],b,id[100007],ls[555],rs[555],gs[555];intxa[555];structpos{intx, y; BOOL operator< (POS W)Const{returny!=w.y?y<w.y:x<w.x;}} vs[100007];intgcdintAintb) { for(intc;b;c=a,a=b,b=c%b); returnA;}intbit[100007];voidXaddintWinta) { for(; w<=n;w+=w&-w) bit[w]^=A;}intXsumintW) { ints=0; for(; w;w-=w&-w) s^=Bit[w]; returns;}intMain () {fread (buf,1,sizeof(BUF), stdin); _ (n); B=sqrt (n); for(intI=1; i<=n;++i) _ (A[i]), id[i]= (i-1)/B,xadd (I,a[i]); for(intI=0; i<=id[n];++i) ls[i]=i*b+1, rs[i]=ls[i]+b-1, dt[i]=1; Rs[id[n]]=N; for(_ (q); q;--q) { if(_c () = ='M'){ intx, Y, Z _ (x); _ (y); ++x; Z=a[x]^X; Xadd (X,Z); A[X]=y; intb=Id[x]; DT[B]=1; for(inti=b+1; i<=id[n];++i) xa[i]^=Z; }Else{ Long Longx; _ (x); for(intI=0, gl=0; i<=id[n];++i) { if(Dt[i]) {Dt[i]=xa[i]=gs[i]=0; intSl=xsum (ls[i]-1); for(intj=ls[i];j<=rs[i];++j) {Gs[i]=gcd (Gs[i],a[j]); SL^=A[j]; VS[J]=(POS) {J,SL}; } std::sort (vs+ls[i],vs+rs[i]+1); } intg=gcd (Gl,gs[i]); if(gl!=g) { intSl=xsum (ls[i]-1); for(intj=ls[i];j<=rs[i];++j) {GL=gcd (Gl,a[j]); SL^=A[j]; if(1ll*gl*sl==x) {printf ("%d\n", J-1); Gotoo; } } }Else if(x%gl==0&&x/gl<1073741824){ intz=x/gl^Xa[i]; POS*it=std::lower_bound (vs+ls[i],vs+rs[i]+1, (POS) {0, z}); if(it!=vs+rs[i]+1&&it->y==z) {printf ("%d\n", it->x-1); Gotoo; }}} puts ("No"); O:; } } return 0;}
bzoj4028: [HEOI2015] Convention number series