QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575686 | #9313. Make Max | masterer | WA | 1ms | 7764kb | C++14 | 1.4kb | 2024-09-19 16:15:59 | 2024-09-19 16:15:59 |
Judging History
answer
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 2e5 + 5;
#define int long long
int t[N], l[N], r[N], ans[N];
void solve()
{
int n;
cin >> n;
vector<int> id[100], arr;
for (int i = 0; i < n; i++) {
cin >> t[i];
arr.push_back(t[i]);
}
sort(arr.begin(), arr.end());
arr.erase(unique(arr.begin(), arr.end()), arr.end());
for (int i = 0; i < n; i++) {
t[i] = lower_bound(arr.begin(), arr.end(), t[i]) - arr.begin();
id[t[i]].push_back(i);
}
stack<int> s;
for (int i = 0; i < n; i++) {
while (!s.empty() && t[i] >= t[s.top()])
s.pop();
l[i] = s.empty() ? -1 : s.top();
s.push(i);
}
while (!s.empty())
s.pop();
for (int i = n - 1; i >= 0; i--) {
while (!s.empty() && t[i] >= t[s.top()])
s.pop();
r[i] = s.empty() ? -1 : t[s.top()];
s.push(i);
}
for (int i = arr.size() - 1; i >= 0; i--) {
for (auto j : id[i]) {
int fa;
if (l[i] == -1 && r[i] == -1)
continue;
else if (l[i] == -1)
fa = r[i];
else if (r[i] == -1)
fa = l[i];
else if (t[l[i]] >= t[r[i]])
fa = r[i];
else
fa = l[i];
ans[j] = ans[fa] + 1;
}
}
int anss = 0;
for (int i = 0; i < n; i++)
anss += ans[i];
cout << anss << endl;
}
signed main()
{
int tt;
cin >> tt;
while (tt--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7764kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 1 8 9
result:
wrong answer 2nd numbers differ - expected: '0', found: '1'