Codeforces 1454B - Unique Bid Auction AcWing 3761. 唯一最小数 每日一题 7.8

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 n participants, the i-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 1-based, i. e. the participants are numbered from 1 to n.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer t(1≤t≤2⋅10^4) — the number of test cases. Then t test cases follow.

The first line of the test case contains one integer n (1≤n≤2⋅10^5) — the number of participants. The second line of the test case contains n integers a_1,a_2,...,a_n(1\leq a_i\leq n) where aiai is the i-th participant chosen number. 

It is guaranteed that the sum of nn does not exceed 2⋅10^5(∑n≤2⋅10^5).

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的整数数组a_1,a_2,...,a_n

        请你找到数组中只出现过一次的数当中最小的那个数。

        输出找到的数的索引编号

        a_1的索引编号为 1,a_2的索引编号为 2,…,a_n的索引编号为 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值