Time Limit: 2 sec / Memory Limit: 1024 MiB
时间限制:2 秒 / 内存限制:1024MiB
Score : 425 points 分数: 425 分
Problem Statement 题目描述
There is a pond with a circumference of M, and on its shore stand one hut and N people.
有一片周长为 M 的池塘,在其岸边有一间小屋和 N 人。
For a real number x (0≤x<M), define point x as the location that is x distance clockwise from the hut.
对于实数 x (0≤x<M) ,定义点 x 为距离小屋 x 顺时针距离的位置。
The i-th person is at point Ai. Multiple people may be standing at the same location.
第 i 个人位于点 Ai 。可能有多个人在同一位置站立。
Additionally, an integer C not greater than N is given. For i=0,1,…,M−1, define Xi as follows:
此外,还给出一个不大于 N 的整数 C 。对于 i=0,1,…,M−1 ,定义 Xi 如下:
- Takahashi starts at point (i+0.5) and begins moving clockwise.
高桥从点 (i+0.5) 开始,顺时针移动。 - Takahashi continues moving (clockwise) as long as the total number of people he has met is less than C, and stops when it becomes C or more. Here, "meeting a person at point y" means that Takahashi reaches point y.
除非遇到的人数达到 C ,否则高桥(按顺时针方向)会继续移动,一旦人数达到 C 或更多,他就停止。在这里,“在 y 遇到一个人”意味着高桥到达 y 。 - Let Xi be the number of people Takahashi met before stopping. Here, if there are multiple people at the point where Takahashi stopped, all the people there are counted as people he met, and particularly, Xi may be greater than C.
令 Xi 为高桥停止前遇到的人数。在这里,如果高桥停止的地方有多个人员,所有这些人员都被计算为遇到的人,特别是 Xi 可能大于 C 。
Find the sum of Xi over i=0,1,…,M−1, that is, i=0∑M−1Xi.
求出 Xi 在 i=0,1,…,M−1 上的总和,即 i=0∑M−1Xi 。
Constraints 约束条件
- 1≤N≤5×105
- 1≤M≤1012
- 0≤Ai≤M−1
- 1≤C≤N
- All input values are integers.
所有输入值都是整数。
Input 输入
The input is given from Standard Input in the following format:
标准输入中给出的输入格式如下:
N M C
A1 A2 … AN
Output 输出
Print the sum of Xi over i=0,1,…,M−1 on a single line.
打印 Xi 在 i=0,1,…,M−1 上的总和。
Sample Input 1 示例输入 1 复制
5 3 2
1 2 1 0 1
Sample Output 1 样本输出 1 复制
9
When i=0, Takahashi starts at point 0.5 and moves clockwise. Then, the following happens:
当 i=0 时,高桥从点 0.5 开始顺时针移动。然后发生以下情况:
- At point 1, he meets the 1st, 3rd, and 5th people, a total of three people, and the total number of people met so far is 3. This is not less than C=2, so Takahashi stops there. Therefore, X0=3.
在点 1 ,他遇到了第 1 个、第 3 个和第 5 个人,总共三个人,到目前为止遇到的总人数是 3 。这不少于 C=2 ,所以高桥在这里停下。因此, X0=3 。
When i=1, Takahashi starts at point 1.5 and moves clockwise. Then, the following happens:
当 i=1 时,高桥从点 1.5 开始顺时针移动。然后发生以下情况:
- At point 2, he meets the 2nd person. The total number of people met so far is 1, so he continues moving.
在点 2 ,他遇到了第 2 个人。到目前为止遇到的人数总共是 1 ,所以他继续前进。 - At point 0, he meets the 4th person, and the total number of people met so far is 2. This is not less than C=2, so Takahashi stops there. Therefore, X1=2.
在点 0 ,他遇到了第 4 个人,到目前为止遇到的总人数是 2 。这不少于 C=2 ,所以高桥在这里停下。因此, X1=2 。
When i=2, Takahashi starts at point 2.5 and moves clockwise. Then, the following happens:
当 i=2 时,高桥从点 2.5 开始顺时针移动。然后发生以下情况:
- At point 0, he meets the 4th person. The total number of people met so far is 1, so he continues moving.
在点 0 ,他遇到了第 4 个人。到目前为止遇到的总人数是 1 ,所以他继续前进。 - At point 1, he meets the 1st, 3rd, and 5th people, a total of three people, and the total number of people met so far is 4. This is not less than C=2, so Takahashi stops there. Therefore, X2=4.
在点 1 ,他遇到了第 1 个、第 3 个和第 5 个人,总共三个人,到目前为止遇到的总人数是 4 。这不少于 C=2 ,所以高桥在这里停下。因此, X2=4 。
Therefore, the answer is X0+X1+X2=3+2+4=9.
因此,答案是 X0+X1+X2=3+2+4=9 。
Sample Input 2 示例输入 2 复制
1 1000000000000 1
1
Sample Output 2 样例输出 2 复制
1000000000000
Regardless of the starting position, Takahashi stops when he meets the only person standing around the pond, who is at point 1.
无论起始位置如何,高桥都会在遇到池塘周围唯一站立的人,即 1 处停下。
Therefore, Xi=1 regardless of i, and the answer is 1012.
因此,无论 i 如何, 1012 ,答案就是 1012 。
思路
直接数学即可。
代码见下
#include<bits/stdc++.h>
using namespace std;
long long n,m,cs,a[500005],b[1000006],c[1000006],ff[1000006],sd=0,op=0,po=0,dk=0;
int main(){
cin>>n>>m>>cs;
for(int i=1;i<=n;i++){
cin>>a[i];
sd=sd+a[i];
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++){
if(i==1||a[i]!=a[i-1]){
b[++b[0]]=a[i];
c[b[0]]=1;
}
else{
c[b[0]]++;
}
}
for(int i=1;i<=b[0];i++){
b[b[0]+i]=b[i];
c[b[0]+i]=c[i];
}
b[0]*=2;
//b[0]++;
po=1;
op=c[1];
for(int i=1;i<=b[0]/2;i++){
while(op<=cs-1){
po++;
op+=c[po];
}
ff[i]=op;
op-=c[i];
}
for(int i=1;i<=b[0]/2;i++){
if(i==1){
dk=dk+ff[i]*b[i]+ff[i]*(m-1-b[b[0]/2]+1);
}
else{
dk=dk+ff[i]*(b[i]-b[i-1]);
}
//cout<<b[i]<<endl;
//cout<<ff[i]<<endl;
}
cout<<dk<<endl;
return 0;
}
626

被折叠的 条评论
为什么被折叠?



