TLE求助
  • 板块CF670C Cinema
  • 楼主microchip
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/11/21 11:55
  • 上次更新2023/11/3 23:51:22
查看原帖
TLE求助
241838
microchip楼主2021/11/21 11:55

嗯,我造了一组大数据,显示运行时间是1.9804s,所以为什么会T呢

#include<bits/stdc++.h>
using namespace std;

int n,m,lan[600005],sci[200005],py[200005],zm[200005];
int b[600005],k,x,happy,bit_happy,ans1,ans2,ans,notle[600005];

void lsh(){
	sort(lan+1,lan+k+1);
	for(int i=1;i<=k;i++){
		if(i==1||lan[i]!=lan[i-1])
			b[++x]=lan[i];
	}
}

int cx(int X){
	return lower_bound(b+1,b+x+1,X)-b;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>sci[i];
		lan[++k]=sci[i];
	}cin>>m;
	for(int i=1;i<=m;i++){
		cin>>py[i];
		lan[++k]=py[i];
	}for(int i=1;i<=m;i++){
		cin>>zm[i];
		lan[++k]=zm[i];
	}lsh();
	for(int i=1;i<=n;i++){
		notle[cx(sci[i])]++;
	}
	for(int i=1;i<=m;i++){
		happy=notle[cx(py[i])];bit_happy=notle[cx(zm[i])];
		if(happy>ans1){
			ans=i;
			ans1=happy;
			ans2=bit_happy;
		}else if(happy==ans1&&bit_happy>ans2){
			ans=i;
			ans1=happy;
			ans2=bit_happy;
		}
	}if(ans1==0&&ans2==0)cout<<1;
	else cout<<ans;
	return 0;
}
2021/11/21 11:55
加载中...