QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575740#9313. Make MaxmastererRE 0ms3576kbC++141.4kb2024-09-19 16:33:542024-09-19 16:33:55

Judging History

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

  • [2024-09-19 16:33:55]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3576kb
  • [2024-09-19 16:33:54]
  • 提交

answer

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 2e5 + 5;
#define int long long
int t[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;
	vector<int> l(n), r(n), ans(n);
	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 : s.top();
		s.push(i);
	}
	for (int i = arr.size() - 1; i >= 0; i--) {
		for (auto j : id[i]) {
			int fa;
			if (l[j] == -1 && r[j] == -1)
				continue;
			else if (l[j] == -1)
				fa = r[j];
			else if (r[j] == -1)
				fa = l[j];
			else if (t[l[j]] > t[r[j]])
				fa = r[j];
			else
				fa = l[j];
			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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Runtime Error

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:


result: