专栏文章
题解:AT_arc069_c [ARC069E] Frequency
AT_arc069_c题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mipojocv
- 此快照首次捕获于
- 2025/12/03 15:22 3 个月前
- 此快照最后确认于
- 2025/12/03 15:22 3 个月前
注意到 S 序列单调递减,否则一定不优。
于是从大到小选择模拟
code:
CPP//created by fqr & cyx in 2025
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define ll long long
#define pb emplace_back
int ff,Ch;
template <typename T> inline void rd(T &x) {
x=0,ff=1,Ch=getchar();
while((Ch<'0'||Ch>'9') && Ch!='-') Ch=getchar();
if(Ch=='-')Ch=getchar(),ff=-1;
while(Ch>='0' && Ch<='9') {
x=(x<<1)+(x<<3)+Ch-'0';
Ch=getchar();
}
x*=ff;
}
template <typename T,typename ...Args> inline void rd(T &x,Args &...args) {
rd(x), rd(args...);
}
using namespace std;
const int N=1e5+5;
int n;
int a[N],p[N];
ll ans[N];
signed main() {
#ifdef LOCAL
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
#endif
rd(n);
for(int i=1; i<=n; i++)
rd(a[i]),p[i]=i;
sort(p+1,p+1+n,[&](const int &x,const int &y) {
return a[x]>a[y];
});
ll sum=a[p[1]];
for(int i=2,lst=1; i<=n+1; i++) {
if(p[i]<p[lst]) {
ans[p[lst]]=sum-1ll*(i-1)*a[p[i]];
sum=(i-1)*a[p[i]];
lst=i;
}
sum+=a[p[i]];
}
for(int i=1; i<=n; i++)
printf("%lld\n",ans[i]);
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...