QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213012 | #5500. Bars | ahsoltan | RE | 0ms | 3600kb | C++20 | 1.3kb | 2023-10-14 05:10:37 | 2023-10-14 05:10:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct pt {
int x, y;
friend pt operator-(pt a, const pt& b) {
return {a.x - b.x, a.y - b.y};
}
};
ll cross(pt a, pt b) {
return 1ll * a.x * b.y - 1ll * a.y * b.x;
}
ll len(pt a) {
return 1ll * a.x * a.x + 1ll * a.y * a.y;
}
const int N = 500500;
int n;
pt a[N];
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].y;
a[i].x = i;
}
n++;
a[n] = {0, 0};
sort(a, a + n, [&] (auto p, auto q) {
ll c = cross(p, q);
if (c == 0) {
return len(p) < len(q);
}
return c < 0;
});
//for (int i = 0; i < n; i++) {
// cerr << a[i].x << ' ' << a[i].y << '\n';
//}
vector<int> s;
s.push_back(0);
s.push_back(1);
for (int i = 2; i < n; i++) {
while (ssize(s) > 1 && cross(a[i] - a[s.back()], a[s.back()] - a[s[ssize(s) - 2]]) < 0) {
s.pop_back();
}
s.push_back(i);
}
//for (int i : s) {
// cerr << a[i].x << ' ' << a[i].y << '\n';
//}
assert(ssize(s) >= 3);
ll ans = 0;
for (int i = 2; i < ssize(s); i++) {
if (a[s[i]].x > a[s[i - 1]].x) {
ans += 1ll * (a[s[i]].x - a[s[i - 1]].x) * (a[s[i]].y + a[s[i - 1]].y);
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
2 4 5 2 2 6 5 1 5 4 4 1
output:
33 29
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
10000 4 5 2 2 6 5 1 5 4 4 1 197 763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...
output:
33 29 382465638565 663641330002 550288673161 457131718959 296831555532 875760099157 632212648574 585065822084 384294231416 726411664707 108880998408 176271639182 583336233523 198176447312 0 481855390366 604809474440 585714003958 142179517404 826500613072 975377092201 921110239612 361743172565 700367...