QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647424 | #9313. Make Max | qqsmr | WA | 0ms | 4100kb | C++14 | 1.4kb | 2024-10-17 14:03:04 | 2024-10-17 14:03:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, a[N], lef[N], rig[N];
stack<int> s;
inline int read() {
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int main () {
int t = read();
while (t--) {
n = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= n; i++) {
if (s.empty() || a[i] < a[s.top()]) s.push(i);
else {
while (!s.empty() && a[i] >= a[s.top()]) {
rig[s.top()] = i;
s.pop();
}
s.push(i);
}
}
while (!s.empty()) rig[s.top()] = n + 1, s.pop();
for (int i = n; i; i--) {
if (s.empty() || a[i] < a[s.top()]) s.push(i);
else {
while (!s.empty() && a[i] >= a[s.top()]) {
lef[s.top()] = i;
s.pop();
}
s.push(i);
}
}
long long ans = 0LL;
for (int i = 1; i <= n; i++) {
if (!lef[i] || a[lef[i]] != a[i]) ans += rig[i] - lef[i] - 2;
else ans += rig[i] - i - 1;
}
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4100kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 0
result:
wrong answer 4th numbers differ - expected: '3', found: '0'