QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#416941 | #2070. Heavy Stones | SSH_automaton | WA | 273ms | 50784kb | C++14 | 2.1kb | 2024-05-22 11:21:12 | 2024-05-22 11:21:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 2e5 + 5;
int n, m, a[N], sz;
pll s[N], all[N << 1];
ll t[N], add[N];
vector<pll> ins[N], del[N];
inline bool cmp(const pll &x, const pll &y) {
return x.first * y.second < y.first * x.second;
}
inline pll operator + (const pll &x, const pll &y) {
return pll(x.first + y.first, x.second + y.second);
}
struct BIT {
ll s[N << 1];
inline void add(int x, ll v) {
for (; x <= m; x += x & -x) s[x] += v;
}
inline ll sum(int x) {
ll res = 0;
for (; x; x &= x - 1) res += s[x];
return res;
}
} TS, TL;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; ++i) cin >> a[i], ans += a[i];
for (int i = 1; i <= n; ++i) {
pll cur(a[i], 1);
ll sb = 0;
while (sz && cmp(s[sz], cur)) {
sb += t[sz] + s[sz].second * cur.first;
cur = cur + s[sz];
del[i + 1].emplace_back(s[sz]);
add[i + 1] -= t[sz--];
}
all[++m] = s[++sz] = cur;
t[sz] = sb;
add[i + 1] += sb;
ins[i + 1].emplace_back(cur);
}
sz = 0;
for (int i = n; i >= 1; --i) {
pll cur(a[i], 1);
ll sb = 0;
while (sz && cmp(s[sz], cur)) {
sb += t[sz] + s[sz].second * cur.first;
cur = cur + s[sz];
ins[i].emplace_back(s[sz]);
add[i] += t[sz--];
}
all[++m] = s[++sz] = cur;
t[sz] = sb;
del[i].emplace_back(cur);
add[i] -= sb;
}
for (int i = 1; i <= sz; ++i) ins[1].emplace_back(s[i]), add[1] += t[i];
sort(all + 1, all + m + 1, cmp);
for (int i = 1; i <= n; ++i) {
for (auto pr : del[i]) {
int p = lower_bound(all + 1, all + m + 1, pr, cmp) - all;
TS.add(p, -pr.first), TL.add(p, -pr.second);
ans -= pr.second * TS.sum(p) + pr.first * (TL.sum(m) - TL.sum(p));
}
for (auto pr : ins[i]) {
int p = lower_bound(all + 1, all + m + 1, pr, cmp) - all;
ans += pr.second * TS.sum(p) + pr.first * (TL.sum(m) - TL.sum(p));
TS.add(p, pr.first), TL.add(p, pr.second);
}
ans += add[i];
cout << ans + (n - 2) * a[i] << ' ';
}
cout << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 21960kb
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: 21968kb
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
Wrong Answer
time: 273ms
memory: 50784kb
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:
9992739490690540 9992748080625132 9992662181663126 9992603151935632 9992527359073407 9992578321529814 9992440882367228 9992582978466282 9992449834480106 9992458424203208 9992574387527206 9992505668050470 9992557207737641 9992501373550843 9992402592894620 9992488493237770 9992462724990808 99924884953...
result:
wrong answer 1st lines differ - expected: '9992833979971052 9992833979971...4203005830427 10004203006781811', found: '9992739490690540 9992748080625...142876288283 10004112812468595 '