QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#222097 | #5500. Bars | ucup-team859# | WA | 189ms | 3720kb | C++23 | 2.9kb | 2023-10-21 15:48:26 | 2023-10-21 15:48:26 |
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
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
int mx = 0, pos = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] > mx)
mx = a[i], pos = i;
}
ll ans = 1LL * pos * a[0] + 1LL * (n - pos - 1) * a[n - 1] + 1LL * (n - 1) * mx;
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;
};
vector<int> st;
st.push_back(0);
for (int i = 1; i < pos; ++i) {
while (st.size() > 1) {
int pv = st[st.size() - 2];
if (get_contribution(pv, pos, i, a[i], a[pv], mx) > get_contribution(pv, pos, st.back(), a[st.back()], a[pv], mx)) {
st.pop_back();
} else {
break;
}
}
if (get_contribution(st.back(), pos, i, a[i], a[st.back()], mx) > 0) {
ans += get_contribution(st.back(), pos, i, a[i], a[st.back()], mx);
st.push_back(i);
}
}
st.clear();
st.push_back(n - 1);
for (int i = n - 2; i > pos; --i) {
while (st.size() > 1) {
int pv = st[st.size() - 2];
if (get_contribution(pos, pv, i, a[i], mx, a[pv]) > get_contribution(pos, pv, st.back(), a[st.back()], mx, a[pv])) {
st.pop_back();
} else {
break;
}
}
if (get_contribution(pos, st.back(), i, a[i], mx, a[st.back()]) > 0) {
ans += get_contribution(pos, st.back(), i, a[i], mx, a[st.back()]);
st.push_back(i);
}
}
cout << ans << endl;
}
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: 0ms
memory: 3640kb
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: 189ms
memory: 3720kb
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 405949774633 707051593824 555553065205 3455008376621 815138601109 1016723499740 906156383088 873634227802 768222668583 832096547744 466644027129 343975349197 2923788920934 218812751505 336548832140 561375035556 705184991466 693537209652 408018096564 1248612347683 1162765780788 1393101785732 29...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '405949774633'