QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575674#9313. Make MaxmastererWA 0ms3740kbC++141.3kb2024-09-19 16:12:522024-09-19 16:12:53

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 16:12:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3740kb
  • [2024-09-19 16:12:52]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'