luogu#P8313. [COCI 2021/2022 #4] Izbori
[COCI 2021/2022 #4] Izbori
Problem Description
Mr. Malnar is running for county prefect. This county has houses, and each house has one resident. Mr. Malnar knows that the winner of an election is not necessarily the best candidate, but the one who holds the best banquet before the election. Therefore, a few days before the election, he will invite the residents living in houses to , and prepare them a luxurious dinner.
Mr. Malnar knows every resident’s favorite dish. At the banquet, he will prepare the dish that is liked by the majority of people. If a person gets to eat their favorite dish, they will vote for Mr. Malnar. But if they do not get to eat their favorite dish, they will vote for Mr. Vlado. Residents who do not come to the banquet will forget about the election and will not vote at all. If a candidate gets support from more than half of the people who voted, they will win the election.
Mr. Malnar wants to know how many pairs can make him win the election.
Input Format
The first line contains an integer , the number of houses.
The second line contains integers , where is the favorite dish of the resident in the -th house.
Output Format
Output a single line containing the number of pairs that can make Mr. Malnar win the election.
2
1 1
3
3
2 1 2
4
5
2 2 1 2 3
10
Hint
Sample 2 Explanation
The pairs that can make Mr. Malnar win the election are: .
Constraints
This problem uses bundled subtasks.
- Subtask 1 (10 pts): .
- Subtask 2 (15 pts): .
- Subtask 3 (15 pts): .
- Subtask 4 (70 pts): No additional constraints.
For of the testdata, $1 \le l \le r \le n \le 2\times10^5,1 \le a_i \le 10^9$.
Notes
The score of this problem follows the original COCI settings, with a full score of .
Translated from T3 Izbori of COCI2021-2022 CONTEST #4.
Translated by ChatGPT 5