Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program
Problem Description
DreamGrid has an integer sequence a1,a2,...,an and he likes it very much. Unfortunately, his naughty roommate BaoBao swapped two elements ai and aj (1<=i<j<=n) in the sequence when DreamGrid wasn't at home. When DreamGrid comes back, he finds with dismay that his precious sequence has been changed into a1,a2,...,ai-1,aj,ai+1,...,aj-1,ai,aj+1,...an
What's worse is that DreamGrid cannot remember his precious sequence. What he only remembers are the two values
Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program
Given the sequence after swapping and the two values DreamGrid remembers, please help DreamGrid count the number of possible element pairs (ai,aj) BaoBao swaps.
Note that as DreamGrid is poor at memorizing numbers, the value of x or y might not match the sequence, and no possible element pair can be found in this situation.
Two element pairs (ai,aj) (1<=i<j<=n) and (ap,aq) (1<=p<q<=n) are considered different if i≠p or j≠q.
Input
There are multiple test cases. The first line of the input contains an integer T, indicating the number of test cases. For each test case:
The first line contains three integers n, x and y (2<=n<=10^5,1<=x,y<=10^18), indicating the length of the sequence and the two values DreamGrid remembers.
The second line contains n integers b1,b2,...,bn (1<=bi<=10^5), indicating the sequence after swapping. It's guaranteed that
Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program
and
Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program
.
It's guaranteed that the sum of n of all test cases will not exceed 2*10^6.
Output
For each test case output one line containing one integer, indicating the number of possible element pairs BaoBao swaps.
Sample Input
2
6 61 237
1 1 4 5 1 4
3 20190429 92409102
1 2 3
Sample Output
2
Hint
For the first sample test case, it’s possible that BaoBao swaps the 2nd and the 3rd element, or the 5th and the 6th element.
題意:t 組資料,每組給出 n 個數的序列和 x、y,現在這個序列中兩個數可能被交換了, x、y 的值是交換前的值,并且計算方式已經給出,問原序列中可能交換的數的對數
思路:
假設交換了 (i,j),那麼:i*a[i] -> i*a[j],j*a[j] -> j*a[i]
是以對于原來的 x、y 有:
Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program
可以得到:
Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program
将得到的兩個式子相除,有:
Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program
然後根據式子左端
Element Swapping(ZOJ-4101)Problem DescriptionInputOutputSample InputSample OutputHintSource Program