QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85774 | #5693. 众数 | xiafan8050 | WA | 11ms | 4268kb | C++20 | 1.4kb | 2023-03-08 15:02:16 | 2023-03-08 15:02:19 |
Judging History
answer
/**
* @author: XiaFan
* @date: 2023-03-08 14:01
**/
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
std::vector<int> b(n);
std::iota(b.begin(), b.end(), 0);
std::sort(b.begin(), b.end(), [&](int x, int y) {
return a[x] < a[y];
});
std::vector<bool> vis(n);
std::vector<int> ssum(n);
int ans = 0, sum = 0, lastid = -1;
for (int i = n - 1, j = 0; i >= 0; i--) {
if (vis[i]) {
continue;
}
vis[i] = true;
if (lastid != -1) {
a[i] -= a[lastid];
}
for (; j < n; j++) {
int id = b[j];
if (a[id] > a[i]) {
break;
} else {
sum += a[id];
vis[id] = true;
}
}
if (j < n)
sum += a[i];
ssum[i] = sum;
if (lastid == -1) {
ans += (i + 1) * ssum[i];
} else {
ans += (i + 1) * (ssum[i] - ssum[lastid]);
}
lastid = i;
}
// for (auto i : ssum) {
// std::cerr << i << " ";
// }
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 4268kb
input:
99991 3 3 3 4 3 6 4 2 2 5 3 2 3 5 3 3 2 1 2 3 4 2 3 4 3 3 3 4 3 3 3 2 3 2 3 2 4 3 3 2 3 5 3 5 4 2 4 3 3 1 3 2 2 3 4 2 3 3 2 2 4 5 3 2 3 3 1 3 3 4 1 3 4 5 1 1 3 4 2 4 3 2 5 3 3 2 2 2 4 2 4 2 2 4 2 4 3 3 2 3 2 2 1 4 3 1 3 1 2 2 3 1 1 5 2 1 2 2 3 3 1 4 4 4 3 3 3 3 1 3 3 5 5 4 4 3 3 3 4 3 6 5 3 1 1 2 2 ...
output:
-516437292
result:
wrong answer 1st lines differ - expected: '4973056284288', found: '-516437292'