QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#382281 | #2070. Heavy Stones | chenxinyang2006 | TL | 0ms | 3888kb | C++14 | 1.9kb | 2024-04-08 10:46:46 | 2024-04-08 10:46:47 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n;
int a[200005];
ll ssum;
bool cmp(pll s,pll t){//s 放在前面,好吗
return s.second * t.first >= t.second * s.first;
}
vector <pll> sta,res;
ll ans;
void emplace(int i){
sta.eb(mkp(a[i],1));
pll temp;
while(SZ(sta) >= 2 && cmp(sta[SZ(sta) - 2],sta.back())){
ans += sta.back().second * sta[SZ(sta) - 2].first;
temp = sta.back();
sta.pop_back();
sta[SZ(sta) - 1].first += temp.first;
sta[SZ(sta) - 1].second += temp.second;
}
}
void solve(int k){
ans = 0;
sta.clear();
rep(i,1,k - 1) emplace(i);
swap(res,sta);
per(i,n,k + 1) emplace(i);
while(!res.empty()){
sta.eb(res.back());
res.pop_back();
}
sort(sta.begin(),sta.end(),cmp);
ll sum = 1;
for(pll I:sta){
ans += I.first * sum;
sum += I.second;
}
printf("%lld ",n * ssum - ans - a[k]);
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&n);
rep(i,1,n){
scanf("%d",&a[i]);
ssum += a[i];
}
rep(k,1,n) solve(k);
printf("\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
5 2 1 3 5 4
output:
35 35 36 43 49
result:
ok single line: '35 35 36 43 49 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
10 18 37 81 6 58 99 87 34 75 9
output:
2637 2637 2657 2657 2695 2949 2995 2905 2880 2880
result:
ok single line: '2637 2637 2657 2657 2695 2949 2995 2905 2880 2880 '
Test #3:
score: -100
Time Limit Exceeded
input:
200000 479735 430060 863649 878892 889364 241972 927862 32858 714406 674598 88114 438434 167733 457299 951288 510096 635193 504974 649221 617914 223711 812277 364169 746142 836563 825312 994240 198961 567906 905208 509572 744710 891294 928176 833980 985385 858440 50835 86130 324862 796245 935992 383...
output:
9992833979971052 9992833979971052 9992833980354966 9992779245594768 9992703452732543 9992625566170070 9992625565960956 9992591568400874 9992591568400874 9992591568189384 9992591567396390 9992591567396390 9992591567476009 9992591567864059 9992591571455644 9992591572452874 9992591574009688 99925915745...