#P4108. [HEOI2015] 公约数数列

    ID: 3044 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015各省省选河北枚举,暴力最大公约数,gcd块状链表,块状数组,分块

[HEOI2015] 公约数数列

Description

Design a data structure. Given a sequence of positive integers a0,a1,,an1a_0, a_1, \cdots, a_{n - 1}, you need to support the following two operations:

  1. MODIFY id x\text{\texttt{MODIFY} \textit{id} \textit{x}}: set aida_{id} to xx.
  2. QUERY x\text{\texttt{QUERY} \textit{x}}: find the smallest integer pp (0p<n0 \le p < n) such that $\gcd(a_0, a_1, \cdots, a_p) \times \operatorname{xor}(a_0, a_1, \cdots, a_p) = x$. Here xor(a0,a1,,ap)\operatorname{xor}(a_0, a_1, \cdots, a_p) denotes the xor-sum of a0,a1,,apa_0, a_1, \cdots, a_p, and gcd\gcd denotes the greatest common divisor.

Input Format

The first line contains a positive integer nn. The next line contains nn positive integers a0,a1,,an1a_0, a_1, \cdots, a_{n - 1}. The next line contains a positive integer qq, the number of queries. Each of the next qq lines contains one query, in the format described above.

Output Format

For each QUERY\texttt{QUERY}, output the result on a separate line. If no such pp exists, output no.

10
1353600 5821200 10752000 1670400 3729600 6844320 12544000 117600 59400 640
10
MODIFY 7 20321280
QUERY 162343680
QUERY 1832232960000
MODIFY 0 92160
QUERY 1234567
QUERY 3989856000
QUERY 833018560
MODIFY 3 8600
MODIFY 5 5306112
QUERY 148900352
6
0
no
2
8
8

Hint

Constraints

  • For 30% of the testdata, n104n \le 10^4, q1000q \le 1000.
  • For 100% of the testdata, n105n \le 10^5, q10000q \le 10000, 1ai1091 \le a_i \le 10^9, in QUERY\texttt{QUERY} operations x1018x \le 10^{18}, in modify operations 0id<n0 \le id < n, 1x1091 \le x \le 10^9.

Translated by ChatGPT 5