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.