2011: Mex Query

题目描述:
Give nn non-negative integers, please find the least non-negative integer that doesn’t occur in the nn numbers.

输入:
The first line is an integer TT, representing the number of test cases.

For each test case:
The first line of each test case is an integer nn.

The second line of each test case are nn non-negative integers a_ia i​ .T \leq 10T≤10n \leq 2 \times 10^5n≤2×10 5 0 \leq a_i < 2^{31}0≤a i<2 31
输出:
or each test case, output a line with the answer.

样例输入
2
4
4 0 1 3
2
1 1
样例输出
2
0

//						佛祖保佑代码无bug
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \\|     |//  `.
//                     /  \\|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \\\  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//					美女保佑代码无BUG
//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ````':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
//
//
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define ll long long
#define dd double
using namespace std;

ll a[200005];
int main() {
	ll t, n;
	cin >> t;
	while (t--) {
		ll flag = 0;
		cin >> n;
		memset(a, 0, sizeof(a));
		for (ll i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		if (a[0] != 0) {
			cout << "0" << endl;
			continue;
		}
		ll z = a[0];
		ll q = 1;
		for (ll i = 1; i < n; i++) {
			if (a[i] != z + q) {
				if (a[i] >= 0 && a[i] <= z + 1) {
					continue;
				}
			}
			else if (a[i] == z + q) {
				z++;
			}
			else {
				flag = 1;
				cout << z + q << endl;
			}
		}
		if (flag == 0) {
			cout << z + q << endl;
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值