#P4108. [HEOI2015] 公约数数列

    ID: 4825 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2015各省省选河北枚举

[HEOI2015] 公约数数列

Problem Description

Design a data structure. Given a sequence of positive integers a0,a1,⋯ ,an−1a_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 (0≤p<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,⋯ ,an−1a_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, n≤104n \le 10^4, q≤1000q \le 1000.
  • For 100% of the testdata, n≤105n \le 10^5, q≤10000q \le 10000, 1≤ai≤1091 \le a_i \le 10^9, in QUERY\texttt{QUERY} operations x≤1018x \le 10^{18}, in modify operations 0≤id<n0 \le id < n, 1≤x≤1091 \le x \le 10^9.

Translated by ChatGPT 5