QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#576421 | #9313. Make Max | jiankiyo | WA | 0ms | 3664kb | C++14 | 1.5kb | 2024-09-19 20:18:17 | 2024-09-19 20:18:19 |
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);
}
}
while (!s.empty()) lef[s.top()] = 0, s.pop();
long long ans = 0LL;
for (int i = 1; i <= n; i++) {
if ( lef[i]!= 0&&a[lef[i]] != a[i]) ans += rig[i] - lef[i] - 2;
else if(a[lef[i]] == a[i]) continue;
else if (lef[i]== 0)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: 3664kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
0 0 0 0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'