QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#568851#9313. Make MaxluoshuiTL 0ms3636kbC++141.2kb2024-09-16 18:52:212024-09-16 18:52:21

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int N=2e5+5;
ll t,n;
vector<int>visit;
struct xy{
   ll zhi;
   int point;
}a[N];
bool cmp(xy x,xy y){
	return x.zhi>y.zhi;
}
void solve(){
	cin>>n;
	ll sum=0;
	visit.clear();
	for(int i=0;i<n;i++){cin>>a[i].zhi;a[i].point=i;}
	sort(a,a+n,cmp);
    ll x=a[0].zhi,k=0;
    visit.push_back(a[0].point);
    for(k=1;k<n;k++){
    	if(a[k].zhi!=x)break;
    	visit.push_back(a[k].point);
	}
//	cout<<sum<<endl;
	for(int i=k;i<n;i++){
		x=a[i].zhi;
		int v1=-1,w=i;
		while(x==a[w].zhi&&w<n){
			int u=a[w].point;
			int v=upper_bound(visit.begin(),visit.end(),u)-visit.begin();
			if(v==0&&v!=v1){
				sum+=visit[v];
				v1=v;
			}
			else if(v==visit.size()&&v!=v1){
				sum+=n-visit[v-1]-1;
				v1=v;
			}
			else{
				if(v!=v1){
				    sum+=visit[v]-visit[v-1]-1;
				    v1=v;
				}
			}
			w++;
		}
		for(int k=i;i<w;i++){
			int u=a[i].point;
			auto v=upper_bound(visit.begin(),visit.end(),u);
			visit.insert(v,u);
		}
		i=w-1;
	}
	cout<<sum<<endl;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

詳細信息

Test #1:

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

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:

4084978

result: