B. Unique Bid Auction
1 second 256 megabytes
There is a game called "Unique Bid Auction". You can read more about it here: https://en.wikipedia.org/wiki/Unique_bid_auction (though you don't have to do it to solve this problem).
Let's simplify this game a bit. Formally, there are participants, the -th participant chose the number aiai. The winner of the game is such a participant that the number he chose is unique (i. e. nobody else chose this number except him) and is minimal (i. e. among all unique values of aa the minimum one is the winning one).
Your task is to find the index of the participant who won the game (or -1 if there is no winner). Indexing is -based, i. e. the participants are numbered from to .
You have to answer tt independent test cases.
Input
The first line of the input contains one integer (1≤t≤2⋅) — the number of test cases. Then test cases follow.
The first line of the test case contains one integer (1≤n≤2⋅) — the number of participants. The second line of the test case contains integers where aiai is the -th participant chosen number.
It is guaranteed that the sum of nn does not exceed 2⋅(∑n≤2⋅).
Output
For each test case, print the answer — the index of the participant who won the game (or -1 if there is no winner). Note that the answer is always unique.
题意
给定一个长度为 n的整数数组。
请你找到数组中只出现过一次的数当中最小的那个数。
输出找到的数的索引编号。
的索引编号为 1,的索引编号为 2,…,的索引编号为 n。
思路
没啥好思路的,拿东西存然后扫一遍...
代码
#include<stack>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#include<deque>
#include<iostream>
#include<map>
#include<set>
#include<iomanip>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N = 2e5+7;
int T,n,a[N],x,pos[N];
int ans;
signed main()
{
#ifndef ONLINE_JUDGE
freopen("IO\\in.txt","r",stdin);
freopen("IO\\out.txt","w",stdout);
#endif
IOS
cin>>T;
while (T--)
{
cin>>n;
memset(a,0,sizeof(a));
for (int i=1;i<=n;i++)
{
cin>>x;
a[x]++;
pos[x]=i;
}
ans=-1;
for (int i=1;i<=n;i++)
if (a[i]==1)
{
ans=pos[i];
break;
}
cout<<ans<<endl;
}
return 0;
}
//CF1454B