QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570603#9313. Make MaxSHOUUOHS#TL 1ms5812kbC++141.5kb2024-09-17 16:41:172024-09-17 16:41:17

Judging History

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

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

answer

#include<bits/stdc++.h>
#define ll long long
int read()
{
	int x=0; bool f=0; char ch=getchar();
	while(! isdigit(ch)) f|=(ch == '-'),ch=getchar();
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return f ? -x : x;
}
using namespace std;
const int N=2e5+10;
int n,L[N],R[N]; ll res;
pair<int,int> a[N]; 

set<int> pl;
struct cp
{
	bool operator () (int a,int b) {
		return a > b;
	}
} ;
set<int,cp> yl;

bool cmp(pair<int,int> a,pair<int,int> b)
{
	if(a.first != b.first) return a.first > b.first;
	return a.second > b.second;
}
bool cmp1(pair<int,int> a,pair<int,int> b)
{
	if(a.first != b.first) return a.first > b.first;
	return a.second < b.second;
}
int main()
{
	int t=read();
	while(t -- )
	{
		res=0;
		
		yl.clear(); pl.clear(); n=read();
		for(int i=1;i<=n;i++) a[i].first=read(),a[i].second=i;
		
		sort(a+1,a+1+n,cmp);
		R[a[1].second]=n; pl.insert(a[1].second);
		for(int i=2;i<=n;i++)
		{
			auto tmp=upper_bound(pl.begin(),pl.end(),a[i].second);
			if(tmp == pl.end()) R[a[i].second]=n;
			else R[a[i].second]=(*tmp)-1;
			
			pl.insert(a[i].second);
		}
		
		sort(a+1,a+1+n,cmp1); 
		L[a[1].second]=1; yl.insert(a[1].second);
		for(int i=2;i<=n;i++)
		{
			auto tmp=upper_bound(yl.begin(),yl.end(),a[i].second,greater<int>());
			if(tmp == yl.end()) L[a[i].second]=1;
			else L[a[i].second]=(*tmp)+1;
			
			yl.insert(a[i].second);
		}
		
		for(int i=1;i<=n;i++) res+=(R[i]-L[i]);
		printf("%lld\n",res);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: