QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#783223 | #2070. Heavy Stones | blackslex | WA | 179ms | 75780kb | C++14 | 2.8kb | 2024-11-26 02:02:14 | 2024-11-26 02:02:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int n;
struct info {
int c0, c1, cans;
info() : c0(0), c1(0), cans(0) {}
info(int c0, int c1) : c0(c0), c1(c1), cans() {}
info(int c0, int c1, int cans) : c0(c0), c1(c1), cans(cans) {}
friend info operator + (const info &p1, const info &p2) {
return info(p1.c0 + p2.c0, p1.c1 + p2.c1, p1.cans + p2.cans + 1LL * p1.c1 * p2.c0);
}
} segm[N * 8];
using P = pair<info, int>;
void upd (int l, int r, int idx, int pos, info val) {
if (l == r) return void(segm[idx] = val);
int mid = (l + r) >> 1;
if (pos <= mid) upd(l, mid, idx * 2 + 1, pos, val);
else upd(mid + 1, r, idx * 2 + 2, pos, val);
segm[idx] = segm[idx * 2 + 1] + segm[idx * 2 + 2];
}
bool cmp (const info &p1, const info &p2) {
return 1LL * p1.c0 * p2.c1 > 1LL * p2.c0 * p1.c1;
}
int main() {
scanf("%d", &n);
vector<int> a(n);
ll sum = 0;
for (auto &e: a) scanf("%d", &e), sum += e;
vector<info> va, vb;
vector<int> va2, vb2;
vector<vector<int>> adda(n, vector<int>()), dela(n, vector<int>());
vector<vector<int>> addb(n, vector<int>()), delb(n, vector<int>());
vector<P> c;
int idx = 0;
for (int i = 0; i < n; i++) {
info cur = info(a[i], 1);
while (!va.empty() && cmp(cur, va.back())) {
auto x = va.back(); va.pop_back();
dela[i].emplace_back(va2.back()); va2.pop_back();
cur = x + cur;
}
va.emplace_back(cur);
c.emplace_back(cur, idx);
adda[i].emplace_back(idx);
va2.emplace_back(idx++);
}
for (int i = n - 1; i >= 0; i--) {
info cur = info(a[i], 1);
while (!vb.empty() && cmp(cur, vb.back())) {
auto x = vb.back(); vb.pop_back();
delb[i].emplace_back(vb2.back()); vb2.pop_back();
cur = x + cur;
}
vb.emplace_back(cur);
c.emplace_back(cur, idx);
addb[i].emplace_back(idx);
vb2.emplace_back(idx++);
}
sort(c.begin(), c.end(), [&] (const P &p1, const P &p2) {
return cmp(p1.first, p2.first);
});
int csz = c.size();
vector<int> cc(csz);
for (int i = 0; i < csz; i++) cc[c[i].second] = i;
for (auto &e: vb2) upd(0, csz - 1, 0, cc[e], c[cc[e]].first);
vector<ll> ans(n);
for (int i = 0; i < n; i++) {
for (auto &e: addb[i]) upd(0, csz - 1, 0, cc[e], info());
for (auto &e: delb[i]) upd(0, csz - 1, 0, cc[e], c[cc[e]].first);
ans[i] = segm[0].cans;
for (auto &e: dela[i]) upd(0, csz - 1, 0, cc[e], info());
for (auto &e: adda[i]) upd(0, csz - 1, 0, cc[e], c[cc[e]].first);
}
for (int i = 0; i < n; i++) printf("%lld ", ans[i] + sum + 1LL * a[i] * (n - 2));
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 22552kb
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: 22868kb
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: 179ms
memory: 75780kb
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:
197428835820 184270603904 271216960540 275838445712 277354994815 147928824790 285283549992 105341121002 241464989380 233027410782 116568117100 185832680802 133668717333 191343888646 290034686344 199981794496 228010029047 201017271633 230067180449 221750774962 146665846997 261889825038 173801285361 2...
result:
wrong answer 1st lines differ - expected: '9992833979971052 9992833979971...4203005830427 10004203006781811', found: '197428835820 184270603904 2712...4452 159507379772 189087279475 '