P17452 Standard Card Packs / Card Packs
Description
You are given two coprime positive integers $p$ and $q$. There are $pq$ different cards, numbered $0,1,\ldots,pq-1$.
In the game, there are two types of standard card packs:
- Type 1 standard packs: there are $p$ kinds, labeled $u$ ($0\le u
Input Format
The first line contains four integers $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$).
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i
Output Format
For each `2 l r` operation, if the specified cards can be partitioned exactly into several standard card packs, output `YES` on one line; otherwise output `NO` on one line.
Explanation/Hint
When $p=2,q=3$:
- There are two Type 1 standard packs: $\{0,2,4\},\{1,3,5\}$.
- There are three Type 2 standard packs: $\{0,3\},\{1,4\},\{2,5\}$.
For the first query, the multiset of cards in the interval is $\{0,0,2,3,4\}$. It can be split into $\{0,2,4\}+\{0,3\}$, so the output is `YES`.
For the last query, the multiset in the interval is $\{1,4\}$. It is exactly one Type 2 standard pack, so the output is `YES`.
Translated by ChatGPT 5