QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575674 | #9313. Make Max | masterer | WA | 0ms | 3740kb | C++14 | 1.3kb | 2024-09-19 16:12:52 | 2024-09-19 16:12:53 |
Judging History
answer
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
int t[100], l[100], r[100], ans[100];
vector<int> id[100], arr;
signed main()
{
int n;
cin >> n;
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;
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3740kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
3
result:
wrong answer 1st numbers differ - expected: '1', found: '3'