先发掘性质:

1.xor和gcd均满足交换律与结合率。

2.前缀gcd最多只有O(log)个。

但并没有什么数据结构能同时利用这两个性质,结合Q=10000,考虑分块。

对每块记录这几个信息:

1.块内所有数的gcd与异或和。

2.将块内所有前缀异或和放入一个数组排序。

查询时从前往后遍历每个块:

1.若当前块不使gcd改变,二分查找是否存在答案。

2.若改变,暴力查找答案。

复杂度(设块大小为S,值域为M):

1.修改复杂度$O(S\log S)$

2.查询复杂度$O(S\log M+\frac{n}{S}\log S)$。

当$S=\sqrt{n}$时复杂度最优,为$O(Q\sqrt{n}\log n)$。

 #include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=,K=;
char op[];
int n,B,tot,Q,ans,L[K],R[K];
ll x,k,a[N],G[K],X[K];
struct P{ ll x; int id; }p[N];
bool operator <(const P &a,const P &b){ return (a.x==b.x) ? a.id<b.id : a.x<b.x; } ll gcd(ll a,ll b){ return b ? gcd(b,a%b) : a; } void build(int x){
G[x]=X[x]=a[L[x]]; p[L[x]]=(P){X[x],L[x]};
rep(j,L[x]+,R[x]) G[x]=gcd(G[x],a[j]),X[x]^=a[j],p[j]=(P){X[x],j};
sort(p+L[x],p+R[x]+);
} int find(int l,int r,ll k){
while (l<r){
int mid=(l+r)>>;
if (p[mid].x<k) l=mid+; else r=mid;
}
return r;
} int main(){
freopen("bzoj4028.in","r",stdin);
freopen("bzoj4028.out","w",stdout);
scanf("%d",&n); B=; tot=(n-)/B+;
rep(i,,n) scanf("%lld",&a[i]);
rep(i,,tot) L[i]=(i-)*B+,R[i]=min(n,i*B),build(i);
for (scanf("%d",&Q); Q--; ){
scanf("%s",op);
if (op[]=='M') scanf("%lld%lld",&x,&k),x++,a[x]=k,build((x-)/B+);
else{
scanf("%lld",&x); ll g=a[],t=; bool w=;
rep(i,,tot){
if (gcd(g,G[i])==g){
if (x%g==){
ll k=x/g^t; int ans=find(L[i],R[i],k);
if (p[ans].x==(x/g^t)){ printf("%d\n",p[ans].id-); w=; break; }
}
g=gcd(g,G[i]); t^=X[i];
}else
rep(j,L[i],R[i]){
g=gcd(g,a[j]); t^=a[j];
if (g*t==x){ printf("%d\n",j-); w=; break; }
}
if (w) break;
}
if (!w) puts("no");
}
}
return ;
}

最新文章

  1. Node.js学习——基本模块之fs
  2. 权重和层叠规则决定了CSS样式优先级
  3. SQLALchemy(连表)、paramiko
  4. vsftp &quot;上传 553 Could not create file&quot;
  5. Oracle 存储过程学习
  6. VC++ UTF-8与GBK格式转换
  7. Redhat常见问题
  8. os内存使用管理之unix-AIX篇
  9. jQuery组织您钞四----jQuery操作DOM
  10. MySQL自动化审核平台部署说明
  11. LaTeX的图片插入及排版
  12. mysql用limit时offset越大时间越长
  13. js操作符+和()
  14. 并发系列(5)之 Future 框架详解
  15. L2-013 红色警报 (25 分) (并查集)
  16. vue中@contextmenu在pc和mac中的区别
  17. DOS命令大全(转)
  18. (转载)http和socket之长连接和短连接区别
  19. js 时间戳和日期互转
  20. (笔记)CanOpen协议【CanFestival】移植方法 支持VC、QT、STM32

热门文章

  1. TreeMap put 操作分析
  2. bzoj 1072 状压DP
  3. js_网页导出pdf文件
  4. Ubuntu之镜像iso安装系统
  5. keepalived主备切换后的arp问题【转】
  6. python操作adb代码
  7. Deep Learning基础--理解LSTM网络
  8. STL中heap相关函数
  9. TCP的状态兼谈Close_Wait和Time_Wait的状态
  10. insta php-fpm 的配置