QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575941#9313. Make Max123BVNRE 0ms5684kbC++231.3kb2024-09-19 17:32:532024-09-19 17:32:53

Judging History

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

  • [2024-09-19 17:32:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:5684kb
  • [2024-09-19 17:32:53]
  • 提交

answer

#include<bits/stdc++.h>
#define ft first
#define sd second
#define int long long
using namespace std;
const int N =1e5 + 10, mod=1e9+7;
struct node{
	int l,r,shu,x;
}a[N];
int aa[N],top,n,mx,mn;
void solve() {
	top=0;
	cin>>n;
	aa[0]=-1;
	mx=0;
	mn=2e9+10;
	for(int i=1;i<=n;i++){
		cin>>aa[i];
		mx=max(aa[i],mx);
		if(aa[i]!=aa[i-1]){
			a[++top].x=aa[i];
			a[top].shu=1;
		}
		else a[top].shu++;
		
	}
	
	for(int i=1;i<=top;i++){
		a[i].l=i-1;
		a[i].r=i+1;
//		cout<<a[i].x<<" "<<a[i].shu<<endl;
	}
	a[0].x=a[top+1].x=mx;
	if(a[1].x==mx)a[1].l=1;
	if(a[top].x==mx)a[top].r=top;
	int pos=1,ans=0;
	while(a[a[pos].l].x!=a[pos].x||a[a[pos].r].x!=a[pos].x){
		int l,r;
		l=a[pos].l;
		r=a[pos].r;
		if(a[pos].x>a[r].x){
			pos=r;
		}
		if(a[l].x==a[r].x){
			ans+=a[pos].shu;
			a[l].shu+=a[pos].shu;
			a[l].shu+=a[r].shu;
			a[l].r=a[r].r;
			pos=l;
		}
		else if(a[l].x<a[r].x){
			ans+=a[pos].shu;
			a[l].shu+=a[pos].shu;
			a[l].r=r;
			a[r].l=l;
			pos=l;
		}
		else {
			ans+=a[pos].shu;
			a[r].shu+=a[pos].shu;
			a[l].r=r;
			a[r].l=l;
			pos=r;
		}
	}
	cout<<ans<<endl;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;

	cin >> t;
	while (t--) {
		solve();
	}
}
/*
4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3


*/

详细

Test #1:

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

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: