QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576139#9313. Make MaxXwcWA 35ms6688kbC++141.6kb2024-09-19 18:45:042024-09-19 18:45:07

Judging History

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

  • [2024-09-19 18:45:07]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:6688kb
  • [2024-09-19 18:45:04]
  • 提交

answer

#include <bits/stdc++.h>

#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef double ff;
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

typedef pair<ll, ll> pii;

const int N = 2e5 + 10, M = 1e7, mod = 998244353;

int n, a[N], pos[N];
ll f[N];

int dfs(int u)
{
	if(f[u] != -1) return f[u];
	else {
		return dfs(pos[u]) + 1;
	}
}

void solve()
{
	cin >> n;
	
	for(int i = 1; i <= n; i ++ ) cin >> a[i], f[i] = pos[i] = -1;
	
	stack<int> stk;
	for(int i = 1; i <= n; i ++ ) {
		while(stk.size() && a[i] >= a[stk.top()]) stk.pop();
		if(stk.size()) pos[i] = stk.top();
		else pos[i] = -1;
		stk.push(i);
	}
	
	
	
	while(stk.size()) stk.pop();
	for(int i = n; i >= 1; i -- ) {
		while(stk.size() && a[i] >= a[stk.top()]) stk.pop();
		if(stk.size()) {
			int head = stk.top();
			if(pos[i] == -1) pos[i] = head;
			else {
				if(i - pos[i] == head - i) {
					if(a[head] < a[pos[i]]) pos[i] = head;
				} else {
					if(head - i < i - pos[i]) pos[i] = head;
 				}
			}
		} else pos[i] = max(pos[i], -1);
		stk.push(i);
	}
	
	// for(int i = 1; i <= n; i ++ ) {
		// cout << pos[i] << ' ';
	// }
	// cout << '\n';
	for(int i = 1; i <= n; i ++ ) {
		if(pos[i] == -1) f[i] = 0;
	}
	
	for(int i = 1; i <= n; i ++ ) {
		if(f[i] != -1) continue;
		f[i] = dfs(pos[i]) + 1;
	}
	
	ll ans = 0;
	for(int i = 1; i <= n; i ++ ) {
		ans += f[i];
		// cout << f[i] << ' ';
	}
	cout << ans << '\n';
}

int main()
{
	fastio;
	
	int t = 1;
	cin >> t;

	while( t -- ) solve();
}

詳細信息

Test #1:

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

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
Wrong Answer
time: 35ms
memory: 6688kb

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:

2235680
2369724

result:

wrong answer 1st numbers differ - expected: '4084978', found: '2235680'