QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB

#21392. 卡包

Statistics

给定两个互质的正整数 $p$ 和 $q$。共有 $pq$ 种不同的卡牌,编号为 $0, 1, \ldots, pq - 1$。

有两种类型的标准卡包:

  • 第一类标准卡包:共有 $p$ 种,以 $u$($0 \le u < p$)编号。编号为 $u$ 的卡包包含编号满足 $x \equiv u \pmod{p}$ 的每种卡牌各一张,因此每个卡包恰好包含 $q$ 张卡牌。
  • 第二类标准卡包:共有 $q$ 种,以 $v$($0 \le v < q$)编号。编号为 $v$ 的卡包包含编号满足 $x \equiv v \pmod{q}$ 的每种卡牌各一张,因此每个卡包恰好包含 $p$ 张卡牌。

现在桌面上排列着 $n$ 张卡牌,其中第 $i$ 张卡牌的编号为 $a_i$。你需要处理 $Q$ 次以下两种类型的操作:

  • 1 i x:将第 $i$ 张卡牌的编号替换为 $x$;
  • 2 l r:判断区间 $[l, r]$ 内的所有卡牌是否可以恰好划分为若干个标准卡包。

注意:在重新分装卡牌时,区间内的每张卡牌必须恰好属于一个卡包,且每种标准卡包都可以使用任意多次。

输入格式

第一行包含四个整数 $n, p, q, Q$($1 \le n, p, q, Q \le 3 \times 10^5$,$2 \le p + q \le 3 \times 10^5$,$\gcd(p, q) = 1$)。

第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($0 \le a_i < pq$),表示每张卡牌的初始编号。

接下来 $Q$ 行,每行以 1 i x 或 2 l r 的形式描述一次操作:

  • 对于每次第一类操作,保证 $1 \le i \le n$ 且 $0 \le x < pq$。
  • 对于每次第二类操作,保证 $1 \le l \le r \le n$。

输出格式

对于每次第二类操作,如果指定的卡牌可以恰好划分为若干个标准卡包,则输出 YES;否则输出 NO。

样例

输入格式 1

8 2 3 5
0 0 2 3 4 1 4 2
2 1 5
2 6 8
1 8 5
2 6 8
2 6 7

输出格式 1

YES
NO
NO
YES

说明

当 $p = 2, q = 3$ 时:

  • 有两种第一类标准卡包:$\{0, 2, 4\}$ 和 $\{1, 3, 5\}$。
  • 有三种第二类标准卡包:$\{0, 3\}$、$\{1, 4\}$ 和 $\{2, 5\}$。

对于第一次询问,区间内卡牌的多重集为 $\{0, 0, 2, 3, 4\}$。它可以被划分为 $\{0, 2, 4\} + \{0, 3\}$,因此答案为 YES。

对于最后一次询问,区间内卡牌的多重集为 $\{1, 4\}$。它恰好构成一个第二类标准卡包,因此答案为 YES。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.