Codecraft-18 and Codeforces Round 458 (Div. 1 + Div. 2, combined)
D
Bash and a Tough Math Puzzle
Codeforces
1900
原题
← CE →
翻译中…

Bash likes playing with arrays. He has an array $*a*_{1}, *a*_{2}, ... *a*_{*n*}$ of $*n*$ integers. He likes to guess the greatest common divisor (gcd) of different segments of the array. Of course, sometimes the guess is not correct. However, Bash will be satisfied if his guess is almost correct.

翻译中…

Suppose he guesses that the gcd of the elements in the range $[*l*, *r*]$ of $*a*$ is $*x*$. He considers the guess to be almost correct if he can change at most one element in the segment such that the gcd of the segment is $*x*$ after making the change. Note that when he guesses, he doesn't actually change the array — he just wonders if the gcd of the segment can be made $*x*$. Apart from this, he also sometimes makes changes to the array itself.

翻译中…

Since he can't figure it out himself, Bash wants you to tell him which of his guesses are almost correct. Formally, you have to process $*q*$ queries of one of the following forms:

翻译中…
  • $1 *l* *r* *x*$ — Bash guesses that the gcd of the range $[*l*, *r*]$ is $*x*$. Report if this guess is almost correct.
  • $2 *i* *y*$ — Bash sets $*a*_{*i*}$ to $*y*$.
翻译中…

Note: The array is $1$-indexed.

翻译中…

Input

翻译中…

The first line contains an integer $*n*$ ($1 ≤ *n* ≤ 5·10^{5}$)  — the size of the array.

翻译中…

The second line contains $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 10^{9}$)  — the elements of the array.

翻译中…

The third line contains an integer $*q*$ ($1 ≤ *q* ≤ 4·10^{5}$)  — the number of queries.

翻译中…

The next $*q*$ lines describe the queries and may have one of the following forms:

翻译中…
  • $1 *l* *r* *x*$ ($1 ≤ *l* ≤ *r* ≤ *n*, 1 ≤ *x* ≤ 10^{9}$).
  • $2 *i* *y*$ $(1 ≤ *i* ≤ *n*, 1 ≤ *y* ≤ 10^{9})$.
翻译中…

Guaranteed, that there is at least one query of first type.

翻译中…

Output

翻译中…

For each query of first type, output "YES" (without quotes) if Bash's guess is almost correct and "NO" (without quotes) otherwise.

翻译中…

Note

翻译中…

In the first sample, the array initially is ${2, 6, 3}$.

翻译中…

For query $1$, the first two numbers already have their gcd as $2$.

翻译中…

For query $2$, we can achieve a gcd of $3$ by changing the first element of the array to $3$. Note that the changes made during queries of type $1$ are temporary and do not get reflected in the array.

翻译中…

After query $3$, the array is now ${9, 6, 3}$.

翻译中…

For query $4$, no matter which element you change, you cannot get the gcd of the range to be $2$.

翻译中…

样例

Input #1
3
2 6 3
4
1 1 2 2
1 1 3 3
2 1 9
1 1 3 2
Output #1
YES
YES
NO
InputCopy OutputCopy
Input #2
5
1 2 3 4 5
6
1 1 4 2
2 3 6
1 1 4 2
1 1 5 2
2 5 10
1 1 5 2
Output #2
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
914D
时间限制
2.5 s
内存限制
256 MB
标签
数据结构
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。