对于 100% 的数据,n <= 100000,q <= 10000,a_i <= 10^9 (0 <= i < n),QUERY x 中的 x <= 10^18,MODIFY id x 中的 0 <= id < n,1 <= x <= 10^9.
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 100050
#define tp t[n]
#define L(i) (i-1)*k+1
#define R(i) min(i*k,n)
#define ff() for(int i=L(x);i<=R(x);i++)
#define f(a,b,c) for(int a=b;a<=c;a++)
using namespace std;
typedef long long LL;
int n,m,t[N],a[N],k;
LL g[N],xo[N],q;
struct Mo{LL x;int r;}b[N];
bool cmp(Mo p1,Mo p2) {return p1.x==p2.x?p1.r<p2.r:p1.x<p2.x;}
LL gcd(LL x,LL y){return y==0?x:gcd(y,x%y);}
void rebuild(int x) {g[x] = xo[x] = 0;
ff()g[x]=gcd(g[x],a[i]);ff()xo[x]^=a[i];
b[L(x)]=(Mo){a[L(x)],L(x)};
f(i,L(x)+1,R(x))b[i]=(Mo){b[i-1].x^a[i],i};sort(b+L(x),b+R(x)+1,cmp); }
void modify(){int id,x;scanf("%d%d",&id,&x);a[id+1]=x;rebuild(t[id+1]);}
int lb(int l,int r,int p) {while(l<r){int mid=(l+r)>>1;b[mid].x>=p?r=mid:l=mid+1;}return l;}
void solve() {scanf("%lld",&q);LL sum=0,sg=0;
f(i,1,tp){
if(gcd(g[i],sg)==sg){
if(q%sg!=0){sum^=xo[i];sg=gcd(sg,g[i]);continue;}
LL p =(q/sg)^sum;int pos=lb(L(i),R(i),p);
if(b[pos].x==p){printf("%d\n",b[pos].r-1);return ;}}
else{LL p=sg,cur=sum;
f(j,L(i),R(i)){p=gcd(p,a[j]),cur^=a[j];if(1LL*p*cur==q){printf("%d\n",j-1);return;}}}
sum^=xo[i],sg=gcd(sg,g[i]);}puts("no");}
int main() {scanf("%d",&n);k=sqrt(n);
f(i,1,n)t[i]=(i-1)/k+1,scanf("%d",&a[i]);
f(i,1,tp)rebuild(i);scanf("%d",&m);
f(i,1,m){char s[10];scanf("%s",s+1);s[1]==‘M‘?modify():solve();}return 0;
}