QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#222127 | #5500. Bars | ucup-team859# | WA | 189ms | 3980kb | C++23 | 2.6kb | 2023-10-21 15:58:11 | 2023-10-21 15:58:11 |
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;
};
auto modify_contribs = [&]() {
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)) {
ans -= 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);
}
}
};
modify_contribs();
reverse(a.begin(), a.end());
pos = n - pos - 1;
modify_contribs();
cout << ans << endl;
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3680kb
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: 3980kb
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 378603050861 663641330002 550288673161 453306332331 293964459687 868548409962 625493705360 574046033126 222808872436 705639372251 466644027129 282778834550 580085388344 200375791150 336548832140 482343932398 602958160012 585741864055 408018096564 820863852044 974552060597 920191993574 25758935...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '378603050861'