欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Educational Codeforces Round 24 D. Multicolored Cars(思维)

程序员文章站 2022-06-04 18:51:19
...

题目链接
Educational Codeforces Round 24 D. Multicolored Cars(思维)
Educational Codeforces Round 24 D. Multicolored Cars(思维)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+1;
vector<int>pos[maxn],temp;
int n,A,a[maxn],cnt[maxn],num[maxn],ans[maxn],sum;
int main()
{
	scanf("%d%d",&n,&A);
	for(int i=1;i<=n;++i)
	{
		cnt[i]=cnt[i-1];
		scanf("%d",&a[i]);
		if(a[i]==A) cnt[i]++,sum++,temp.push_back(i);
		pos[a[i]].push_back(i);
	}
	for(int i=1;i<maxn;++i)
	{
		int size=pos[i].size();
		if(i==A||size==0||size<sum) continue;
		for(int j:temp)
		{
			int now=pos[i][num[i]++];
			//cout<<i<<" "<<now<<endl;
			if(now<j) ans[i]++;
		}
		if(ans[i]==sum) {
			printf("%d\n",i);return 0;
		}
	}
	printf("-1\n");
}
相关标签: 思维