#P3770. [CTSC2017] 密钥
[CTSC2017] 密钥
Description
A key is a string of length that contains 1 letter X, letters A, and letters B. For example, when , BAXABAB is a key.
As shown in the figure below, these letters can be arranged in a circle in clockwise order:

Among the letters A, some can be defined as "strong". Specifically, starting from X and walking clockwise to some A, if along the way the number of A is strictly greater than the number of B, then that letter A is called strong.
In the above example, the 1st and 2nd letters A counted clockwise from X are strong, while the 3rd letter A is not strong.
The characteristic value of a key is the number of strong letters A it contains.
The genius child KT gave the following result:
Assume the positions of the letters A are fixed, but the positions of the remaining letters B and 1 letter X are unknown. (Note that there are exactly keys that meet this condition, because X still has possible positions.)
It can be proved that the characteristic values of all these possible keys are pairwise distinct and are exactly .
The following figure is a concrete example. From left to right, the four sub-figures have 3, 2, 1, and 0 strong letters A, respectively.

Similarly, if the positions of the letters B are fixed, then the characteristic values of all keys that meet the condition are also pairwise distinct and are exactly .
Now you need to solve the following three problems:
- Given the positions of all A in the key, when the characteristic value is , where is X located?
- Given the positions of all A in the key, when the characteristic value is , where is X located?
- Given the positions of all B in the key, when the characteristic value is , where is X located?
Note: The positions of the letters of the string are numbered from to .
[Example 1]
Assume , . Then:
- When the positions of A are {2, 4, 6} and the characteristic value is , the position of X is .
- When the positions of A are {2, 4, 6} and the characteristic value is , the position of X is .
- When the positions of B are {2, 4, 6} and the characteristic value is , the position of X is .
[Example 2]
Assume , . Then:
- When the positions of A are {3, 4, 5, 9, 10, 12, 13, 16, 19} and the characteristic value is , the position of X is .
- When the positions of A are {3, 4, 5, 9, 10, 12, 13, 16, 19} and the characteristic value is , the position of X is .
- When the positions of B are {3, 4, 5, 9, 10, 12, 13, 16, 19} and the characteristic value is , the position of X is .
Input Format
There is only one set of testdata.
The first line contains an integer , as described above.
The second line contains an integer seed, which will be used to generate a -element set .
The third line contains an integer , as described above.
It is guaranteed that . .
Under cipher/, there are two files for generating the input data, cipher.cpp/pas. The reading part has been completed. In the array , if , it means is not in set ; otherwise, is in set .
Baidu Netdisk link>> Password: 9vr3 Please compile it yourself.
#include <stdio.h>
#include <string.h>
int p[20000005];
int seed, n, k, S;
int getrand() {
seed = ((seed * 12321) ^ 9999) % 32768;
return seed;
}
void generateData() {
scanf( "%d%d%d", &k, &seed, &S );
int t = 0;
n = k * 2 + 1;
memset(p, 0, sizeof(p));
for( int i = 1; i <= n; ++i ) {
p[i] = (getrand() / 128) % 2;
t += p[i];
}
int i = 1;
while( t > k ) {
while ( p[i] == 0 ) ++i;
p[i] = 0;
--t;
}
while( t < k ) {
while( p[i] == 1 ) ++i;
p[i] = 1;
++t;
}
}
int main() {
generateData();
return 0;
}
Output Format
Output three lines, one number per line, corresponding to the answers to the three subproblems in the description.
That is:
- The first number indicates the position of X when the -element set represents the positions of A and the characteristic value is .
- The second number indicates the position of X when the -element set represents the positions of A and the characteristic value is .
- The third number indicates the position of X when the -element set represents the positions of B and the characteristic value is .
5
3344
2
10
1
2
500000
4545
234567
999992
246922
753067
Hint
[Sample Explanation]
In the first sample, the indices of elements where array is are .
[Constraints and Conventions]
- For 30% of the testdata, .
- For 50% of the testdata, .
- For 100% of the testdata, .
For each test point, the score is the sum of the following three parts:
- If you answer the first question correctly, you will get 3 points.
- If you answer the second question correctly, you will get 4 points.
- If you answer the third question correctly, you will get 3 points.
If you only know part of the answers, please still output three numbers in this required format. Otherwise, you may lose points due to formatting errors.
Translated by ChatGPT 5
京公网安备 11011102002149号