QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593638#7944. Max Minus MinATM12345#WA 3ms5888kbC++171.1kb2024-09-27 15:16:282024-09-27 15:16:28

Judging History

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

  • [2024-09-27 15:16:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5888kb
  • [2024-09-27 15:16:28]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define Ma 1000005 
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



using namespace std;


ll n;
ll a[Ma];

struct node{
	ll w,num;
	bool operator <(const node &A)const{
		return w<A.w;
	}
}t[Ma];



void sol()
{
	cin>>n;
	for (ll i=1;i<=n;i++)
		cin>>a[i],t[i]={a[i],i};
	sort(t+1,t+n+1);
	ll l=1,r=n,ok=t[1].num,ans=t[n].w-t[1].w;
	ll mi=t[n].w;
	for (ll i=n;i>=1;i--)
	{
		if (t[i].num<ok)
		{
			for (ll j=l;j<t[i].num;j++)
				mi=min(mi,a[j]);
			l=max(l,t[i].num);
			
		}
		else
		{
			for (ll j=t[i].num+1;j<=r;j++)
				mi=min(mi,a[j]);
			r=min(r,t[i].num);
		}
		ans=min(ans,max(t[n].w-mi,t[i].w-t[1].w));
	}
	l=1,r=n,ok=t[n].num;
	ll ma=t[1].w;
	for (ll i=1;i<=n;i++)
	{
		if (t[i].num<ok)
		{
			for (ll j=l;j<t[i].num;j++)
				ma=max(ma,a[j]);
			l=max(l,t[i].num);
			
		}
		else
		{
			for (ll j=t[i].num+1;j<=r;j++)
				ma=max(ma,a[j]);
			r=min(r,t[i].num);
		}
		ans=min(ans,max(ma-t[1].w,t[n].w-t[i].w));
	}
	printf("%lld\n",ans);
}



int main()
{
	IOS
	ll tt=1;
	cin>>tt;
	while (tt--)
		sol();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5888kb

input:

4
3
42 42 42
4
1 2 2 1
5
1 100 1 100 1
6
1 2 3 4 5 6

output:

0
0
99
2

result:

ok 4 number(s): "0 0 99 2"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 5888kb

input:

19530
6
2 3 3 3 4 3
6
2 4 4 2 5 5
6
2 5 2 5 1 3
6
4 4 1 2 4 1
5
5 4 5 3 3
5
2 2 1 5 1
6
3 1 2 4 2 3
5
5 5 4 4 5
6
5 3 3 1 4 2
6
3 3 2 4 2 4
6
1 2 4 5 2 5
5
3 4 5 5 3
6
4 3 3 3 4 3
6
1 5 1 2 3 1
5
5 5 2 1 4
6
1 2 5 3 5 2
6
4 5 2 4 5 2
5
2 4 2 4 1
4
2 3 3 3
6
1 2 2 1 4 5
6
3 2 1 3 3 2
6
2 1 1 2 5 3
6
...

output:

1
2
3
3
1
1
2
0
3
2
3
1
1
2
1
3
3
2
0
1
1
2
0
3
2
2
3
1
2
2
3
3
2
2
1
2
2
2
2
2
2
1
2
1
2
1
2
2
2
1
1
4
2
0
2
2
1
0
1
2
1
2
3
1
1
2
3
2
2
1
0
2
1
2
3
2
0
2
0
1
2
0
1
2
2
2
1
3
2
1
2
3
2
1
1
2
2
3
1
1
1
2
2
1
0
1
1
2
2
2
1
2
3
2
1
2
0
3
3
1
0
0
1
2
2
3
4
2
2
1
2
1
2
4
1
1
1
3
2
2
2
1
2
1
2
1
2
2
0
3
...

result:

wrong answer 16th numbers differ - expected: '2', found: '3'