社区讨论
为何桶排计算贡献有问题
P6033[NOIP 2004 提高组] 合并果子 加强版参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhz4888o
- 此快照首次捕获于
- 2025/11/15 01:12 4 个月前
- 此快照最后确认于
- 2025/11/16 13:45 4 个月前
CPP
#include<bits/stdc++.h>
#define rd() read()
#define wt write
#define pc putchar
using namespace std;
namespace IO{
inline int read(){
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-'){
f=-1;
}
c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
inline void write(int x){
if(x<0){
x=-x;
pc('-');
}
if(x>9){
wt(x/10);
pc(x%10+'0');
}
else{
pc(x+'0');
}
return ;
}
}
using namespace IO;
namespace Main{
const int N=1e5+7;
int n,res,cnt,minn=0x3f3f3f3f;
int s[N];
inline void main(){
cnt=n=rd();
for(int i=0;i<n;i++){
int x=rd();
++s[x];
minn=min(minn,x);
}
for(int i=0;i<=100000;i++){
if(s[i]){
res+=i*(((cnt+(cnt-s[i]+1))*s[i])>>1);
cnt-=s[i];
}
}
wt(res-minn);
return ;
}
}
signed main(){
// freopen("1.in","r",stdin);
// freopen("out.out","w",stdout);
Main::main();
return 0;
}
/*
3
1 2 9
*/
回复
共 0 条回复,欢迎继续交流。
正在加载回复...