QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#154761 | #5500. Bars | berarchegas# | WA | 213ms | 28252kb | C++17 | 2.3kb | 2023-08-31 22:01:24 | 2023-08-31 22:01:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll INF = 2e18;
struct no {
int mx, posFirst, posLast;
no(int _mx = 0, int _posFirst = 0, int _posLast = 0) {
mx = _mx;
posFirst = _posFirst;
posLast = _posLast;
}
no operator + (const no &x) const {
no aux;
if (mx == x.mx) {
aux.mx = mx;
aux.posFirst = min(posFirst, x.posFirst);
aux.posLast = max(posLast, x.posLast);
}
else if (mx > x.mx) {
aux = *this;
}
else {
aux = x;
}
return aux;
}
} a[4 * MAXN];
ll v[MAXN];
void build(int node, int i, int j) {
if (i == j) {
a[node] = no(v[i], i, i);
}
else {
int m = (i + j) / 2;
build(2 * node, i, m);
build(2 * node + 1, m + 1, j);
a[node] = a[2 * node] + a[2 * node + 1];
}
}
no query(int node, int i, int j, int ini, int fim) {
if (fim < i || j < ini) return no(0);
if (ini <= i && j <= fim) return a[node];
int m = (i + j) / 2;
return query(2 * node, i, m, ini, fim) + query(2 * node + 1, m + 1, j, ini, fim);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
build(1, 1, n);
ll ans = 0;
vector<int> get = {1, n};
int ini = 1, fim = n;
while (true) {
// cout << ini << ' ' << fim << endl;
int tam = fim - ini - 1;
if (tam == 0) break;
no at = query(1, 1, n, ini + 1, fim - 1);
if (at.mx <= min(v[ini], v[fim])) {
break;
}
else if (at.mx > min(v[ini], v[fim]) && at.mx <= max(v[ini], v[fim])) {
if (v[ini] >= v[fim]) {
get.push_back(at.posLast);
fim = at.posLast;
}
else {
get.push_back(at.posFirst);
ini = at.posFirst;
}
}
else {
get.push_back(at.posFirst);
ini = at.posFirst;
}
}
sort(get.begin(), get.end());
for (int i = 0; i < (int)get.size(); i++) {
// cout << get[i] << ' ';
if (i < (int)get.size() - 1) {
ans += v[get[i]] * (get[i + 1] - get[i]);
}
if (i > 0) {
ans += v[get[i]] * (get[i] - get[i - 1]);
}
}
// cout << '\n';
cout << ans << '\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 27372kb
input:
2 4 5 2 2 6 5 1 5 4 4 1
output:
33 29
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 213ms
memory: 28252kb
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 348594618207 648502397262 530519566119 419319677308 279477203617 786965194600 431805595669 422089825744 208867115146 613185221330 461648192521 282778834550 548846509339 175559404698 336548831210 444912059518 530190318382 463028437647 407336297127 618566552136 742822037261 722371359567 22559385...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '348594618207'