比赛 |
2025.3.18 |
评测结果 |
AAAAAAAAAA |
题目名称 |
公约数数列 |
最终得分 |
100 |
用户昵称 |
darkMoon |
运行时间 |
3.466 s |
代码语言 |
C++ |
内存使用 |
8.16 MiB |
提交时间 |
2025-03-18 21:30:59 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
auto IN = freopen("gcdxor.in", "r", stdin);
auto OUT = freopen("gcdxor.out", "w", stdout);
auto IOS = ios::sync_with_stdio(false);
auto CIN = cin.tie(nullptr);
int mread(){
int x = 0, f = 1;
char c = cin.get();
while(c < '0' || c > '9'){
if(c == '-'){
f = -1;
}
c = cin.get();
}
while(c >= '0' && c <= '9'){
x = x * 10 + c - '0';
c = cin.get();
}
return x * f;
}
const int N = 1e5 + 5, B = 1300;
int n = mread(), a[N], c[N];
struct block{
int l[B], r[B], belong[N], m = ceil(1.0 * n / B), la[B] = {0};
pair<int, int> pa[N];
void build(){
for(int i = 1; i <= m; i ++){
l[i] = r[i - 1] + 1;
r[i] = l[i] + B - 1;
la[i] = 0;
}
r[m] = n;
for(int i = 1; i <= m; i ++){
for(int j = l[i]; j <= r[i]; j ++){
belong[j] = i;
pa[j] = mp(c[j], j);
}
sort(pa + l[i], pa + 1 + r[i]);
}
}
void update(int x, int nl, int nr, int k){
for(int i = l[x]; i <= r[x]; i ++){
c[i] ^= la[x];
if(i >= nl && i <= nr){
c[i] ^= k;
}
pa[i] = mp(c[i], i);
}
la[x] = 0;
sort(pa + l[x], pa + 1 + r[x]);
return;
}
void ch(int nl, int nr, int k){
int x = belong[nl], y = belong[nr];
if(x == y){
update(x, nl, nr, k);
return;
}
update(x, nl, r[x], k);
update(y, l[y], nr, k);
for(int i = x + 1; i < y; i ++){
la[i] ^= k;
}
return;
}
int query(int nl, int nr, int k){
int x = belong[nl], y = belong[nr];
if(x == y){
for(int i = nl; i <= nr; i ++){
if((c[i] ^ la[x]) == k){
return i;
}
}
return -1;
}
for(int i = nl; i <= r[x]; i ++){
if((c[i] ^ la[x]) == k){
return i;
}
}
for(int i = x + 1; i < y; i ++){
int p = lower_bound(pa + l[i], pa + 1 + r[i], mp(k ^ la[i], 0ll)) - pa;
if(p <= r[i] && pa[p].fi == (k ^ la[i])){
return pa[p].se;
}
}
for(int i = l[y]; i <= nr; i ++){
if((c[i] ^ la[y]) == k){
return i;
}
}
return -1;
}
}b;
struct tree{
int v[N << 2] = {0};
void pushup(int x){
v[x] = __gcd(v[x << 1], v[x << 1 | 1]);
return;
}
void build(int x, int nl, int nr){
if(nl == nr){
v[x] = a[nl];
return;
}
int mid = nl + nr >> 1;
build(x << 1, nl, mid);
build(x << 1 | 1, mid + 1, nr);
pushup(x);
return;
}
void ch(int p, int k, int x = 1, int nl = 1, int nr = n){
if(nl == nr){
v[x] = k;
return;
}
int mid = nl + nr >> 1;
if(p <= mid){
ch(p, k, x << 1, nl, mid);
}
else{
ch(p, k, x << 1 | 1, mid + 1, nr);
}
pushup(x);
return;
}
int query(int l, int r, int x = 1, int nl = 1, int nr = n){
if(nl >= l && nr <= r){
return v[x];
}
int mid = nl + nr >> 1, ans = -1;
if(mid >= l){
ans = query(l, r, x << 1, nl, mid);
}
if(mid + 1 <= r){
if(ans == -1){
ans = query(l, r, x << 1 | 1, mid + 1, nr);
}
else{
ans = __gcd(ans, query(l, r, x << 1 | 1, mid + 1, nr));
}
}
return ans;
}
}tr;
signed main(){
for(int i = 1; i <= n; i ++){
a[i] = mread();
c[i] = c[i - 1] ^ a[i];
}
b.build();
tr.build(1, 1, n);
int q = mread();
while(q --){
string op;
cin >> op;
if(op[0] == 'M'){
int x = mread() + 1, k = mread();
k = a[x] ^ k;
a[x] ^= k;
b.ch(x, n, k);
tr.ch(x, k);
}
else{
int x = mread();
int la = 1, now = a[1], ans = -1;
while(la <= n){
int l = la, r = n;
while(l < r){
int mid = l + r + 1 >> 1;
if(tr.query(1, mid) == now){
l = mid;
}
else{
r = mid - 1;
}
}
if(x % now == 0 && x / now <= 2e9){
int tmp = b.query(la, l, x / now);
if(tmp != -1){
ans = tmp;
break;
}
}
la = l + 1;
now = __gcd(now, a[la]);
}
if(ans == -1){
cout << "no\n";
}
else{
cout << ans - 1 << "\n";
}
}
}
return 0;
}