暴力写错
  • 板块灌水区
  • 楼主xyz123
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/31 17:35
  • 上次更新2024/10/31 17:35:42
查看原帖
暴力写错
379926
xyz123楼主2024/10/31 17:35

P4168 暴力都写错了

#include<bits/stdc++.h>
using namespace std;
const int N=40010;
int a[N];
int tot[N],cnt,n,q;
int tmp[N];
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]),tot[i-1]=a[i];
	sort(tot,tot+n);
	cnt=unique(tot,tot+n)-tot;
	for(int i=1;i<=n;i++)	a[i]=lower_bound(tot,tot+cnt,a[i])-tot;
	while(q--){
		int l,r;scanf("%d%d",&l,&r);
		if(l>r)	swap(l,r);
		int x=40009;
		for(int i=l;i<=r;i++){
			tmp[a[i]]++;
			if(tmp[a[i]]>tmp[x]||(tmp[a[i]]==tmp[x]&&a[i]<x))	x=a[i];
		}
		printf("%d\n",tot[x]);
		for(int i=l;i<=r;i++)	tmp[a[i]]--;
	}
	return 0;
}

哪里有问题?

2024/10/31 17:35
加载中...