QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#222227 | #5500. Bars | ucup-team859# | WA | 249ms | 8188kb | C++23 | 2.8kb | 2023-10-21 16:20:50 | 2023-10-21 16:20:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
const int DIM = 5e5 + 1;
int n;
int a[DIM];
pair<int, int> arb[4 * DIM];
void build(int st = 1, int dr = n, int nod = 1) {
arb[nod] = {a[st], st};
if (st == dr)
return;
int mij = (st + dr) / 2;
build(st, mij, nod * 2);
build(mij + 1, dr, nod * 2 + 1);
arb[nod] = max(arb[nod * 2], arb[nod * 2 + 1]);
}
pair<int,int> query(int x, int y, int st = 1, int dr = n, int nod = 1) {
if (x <= st && dr <= y)
return arb[nod];
int mij = (st + dr) / 2;
if (x <= mij && mij + 1 <= y)
return max(query(x, y, st, mij, nod * 2), query(x, y, mij + 1, dr, nod * 2 + 1));
if (x <= mij)
return query(x, y, st, mij, nod * 2);
return query(x, y, mij + 1, dr, nod * 2 + 1);
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
auto get_contribution = [&](int l, int r, int i, int x, int xl, int xr) -> ll {
return 1LL * (r - l) * x - 1LL * (r - i) * xl - 1LL * (i - l) * xr;
};
build();
std::function<ll(int, int)> solve = [&](int l, int r) -> ll {
if (l + 1 >= r)
return 0;
auto res = query(l + 1, r - 1);
int mx = res.first;
int x = res.second;
ll contrib = get_contribution(l, r, x, mx, a[l], a[r]);
if (contrib > 0) {
return contrib + solve(l, x) + solve(x, r);
}
return 0;
};
ll ans = solve(1, n) + 1LL * (n - 1) * (a[n] + a[1]);
cout << ans << "\n";
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5740kb
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: 249ms
memory: 8188kb
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 381268324603 661441328080 530685669075 458946673513 296420749955 870990424556 620297057867 584888108745 225238172734 716027782821 466644027129 282778834550 585094154153 200375791150 336548832140 483213442818 603010006124 586771956643 408018096564 826072001692 975377092201 762279526081 26408806...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '381268324603'