#P7875. 「SWTR-7」IOI 2077
「SWTR-7」IOI 2077
Description
There are candidate contestants in IOI 2077, numbered . Each candidate contestant has an ability value, and all ability values are distinct. The ability value of the -th candidate is . Little A prefers ordered numbers, so he sorts these candidates by ability value in increasing order, i.e. .
The official contestants will be chosen from these candidates. Specifically, all contestants will be a substring of the candidates, i.e. candidates with indices will participate in IOI 2077. Little A’s index is . Since he knows he has been appointed to participate, we must have . There are possible cases of contestants. Each case is described by three numbers , meaning the contestants are the candidates with indices in , and Little A’s index is .
Because he is not strong enough, Little A feels overwhelmed by the coming IOI. He decides to choose some contestants as teammates and help (zuo) each other (bi) during the contest. Specifically, let the number of official contestants be . Then Little A will choose an integer uniformly at random from , and then randomly select people from the contestants as his teammates. However, Little A does not want to look too weak, so his ability value must be the median of the ability values of these people.
As the saying goes, there is strength in numbers. Little A hopes the sum of the ability values of himself and all selected teammates is as large as possible. But before that, he wants to know the expected value of this sum. Output the result modulo , and it is guaranteed that the answer is well-defined under this modulus. For each possible contestants case, you need to compute the answer for that case. To avoid too much output, you only need to compute the XOR of all answers.
Input Format
The first line contains an integer , the Subtask id of this test point.
The second line contains two integers , representing the number of candidate contestants and the total number of cases.
The third line contains integers , representing the ability values of each candidate contestant. It is guaranteed that is increasing.
The next lines each contain three integers describing one possible contestants case.
Output Format
Output one line with one integer, the XOR of all answers.
0
5 2
2 3 5 7 8
1 5 3
2 4 2
499122189
Hint
"Sample 1 Explanation"
-
Query 1:
Since , can be , or .
When : Little A has no teammates, so the expected value is his own ability value .
When : Little A can choose contestants with indices or or or as his teammates. The sums of abilities are respectively, so the expected value is .
When : Little A can only choose everyone, so the expected value is .
Therefore, the expected value is . -
Query 2:
Since , can be or .
When : Little A has no teammates, and the expected value is .
When : Little A cannot make any choice, so the expected value is .
Therefore, the expected value is , which becomes after taking modulo .
.
"Constraints and Conventions"
This problem uses bundled tests.
Let .
- Subtask #0 (1 point): the samples.
- Subtask #1 (10 points): .
- Subtask #2 (20 points): , , .
- Subtask #3 (15 points): , .
- Subtask #4 (15 points): , .
- Subtask #5 (15 points): , .
- Subtask #6 (24 points): no special constraints.
For of the testdata, , , , .
For all test points, the time limit is 1s and the memory limit is 512MB.
"Help / Tips"
About modulo of rational numbers, median.
The input and output size of this problem is extremely large, please pay attention to I/O optimization.
This problem provides a fast input template for signed 32-bit integers, guaranteeing the total reading time does not exceed 250ms:
#define gc getchar()
inline int read(){
int x=0; bool sgn=0; char s=gc;
while(!isdigit(s))sgn|=s=='-',s=gc;
while(isdigit(s))x=(x<<1)+(x<<3)+(s-'0'),s=gc;
return sgn?-x:x;
}
// 如果需要读入直接调用 read() 即可。
// 一个例子(与正解无关,仅供参考):
int t=read(),n=read(),q=read();
int a[2000005],l[2000005],r[2000005],k[2000005];
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=q;i++)l[i]=read(),r[i]=read(),k[i]=read();
// 这样你就可以在 250ms 内读入全部数据了。
"Source"
Sweet Round 07 C.
idea & solution: SSerWarriors_Cat; data: Alex_Wei; validation: chenxia25。
After IOI 2077 ended, Little A successfully AK-ed IOI thanks to his outstanding (dui) performance (you) and great (bang) teamwork (zhu). This made him recall his once-passionate self and the comrades who fought alongside him on the OI path. Now they are far apart, and it has been more than ten years since they last met, but their sincere friendship has not faded, and it will never fade.
"Grandpa, there is a recording in your phone, and it also says 'ycx txdy!'."
"Oh, really? Play it for me.""I AK IOI. I AK ACM World Final. I AK Universe OI. I think all of you are vegetable chickens."
"I AK IOI. I AK ACM World Final. I AK Universe OI. I think all of you are vegetable chickens."
"I AK IOI. I AK ACM World Final. I AK Universe OI. I think all of you ............"
2077.7.7
Translated by ChatGPT 5
京公网安备 11011102002149号