QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567435#9313. Make MaxxunxxxxTL 0ms3804kbC++23809b2024-09-16 11:56:062024-09-16 11:56:06

Judging History

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

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 11:56:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3804kb
  • [2024-09-16 11:56:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct node
{
	int x,i,lz;
}a[200010];
bool cmpx(node a1,node a2)
{
	if(a1.x==a2.x) return a1.i<a2.i;
	return a1.x>a2.x;
}
int n;
long long ans;
void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i].x,a[i].i=i;
	sort(a+1,a+1+n,cmpx);
	
	for(int i=1;i<=n;i++) 
	if(a[i].x==a[i+1].x) a[i].lz=0;
	else a[i].lz=1;
	
	ans=0;
	vector<int>v;
	v.push_back(0);
	v.push_back(n+1);
	for(int i=1;i<=n;i++)
	{
		auto it=upper_bound(v.begin(),v.end(),a[i].i);
		ans+=a[i].i-(*prev(it))-1;
		if(a[i].lz==0&&a[i+1].i>*it) ans+=*it-a[i].i-1;
		if(a[i].lz==1) ans+=*it-a[i].i-1;
		v.insert(it,a[i].i);
	}	
	cout<<ans<<"\n";
	
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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: