本文主要是介绍HHKB Programming Contest 2020 C - Neq Min(树状数组+二分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:
求对于每个前缀的数第一个未出现的非负数
思路:
直接树状数组+二分乱搞
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;const int maxn = 2e5 + 10;int n;
int vis[maxn];
int c[maxn];void add(int x,int v) {while(x < maxn) {c[x] += v;x += x & -x;}
}int sum(int x) {int res = 0;while(x) {res += c[x];x -= x & -x;}return res;
}int Bin() {int l = 1,r = 200005;int ans = 200005;while(l <= r) {int mid = (l + r) >> 1;if(sum(mid) < mid) {r = mid - 1;ans = mid;} else {l = mid + 1;}}return ans;
}int main() {scanf("%d",&n);for(int i = 1;i <= n;i++) {int x;scanf("%d",&x);x++;if(!vis[x]) add(x,1);vis[x] = 1;printf("%d\n",Bin() - 1);}return 0;
}
这篇关于HHKB Programming Contest 2020 C - Neq Min(树状数组+二分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!