Help pls!
# | User | Rating |
---|---|---|
1 | tourist | 3856 |
2 | jiangly | 3747 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3591 |
6 | gamegame | 3477 |
7 | Benq | 3468 |
8 | Radewoosh | 3462 |
9 | ecnerwala | 3451 |
10 | heuristica | 3431 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | -is-this-fft- | 162 |
3 | Dominater069 | 160 |
4 | Um_nik | 158 |
5 | atcoder_official | 157 |
6 | Qingyu | 156 |
7 | adamant | 151 |
7 | djm03178 | 151 |
7 | luogu_official | 151 |
10 | awoo | 146 |
Help pls!
Name |
---|
You can keep an array of Boolean values, with each index representing whether or not you have seen this number in the array. It will be of size n+1, since mex of n elements is at most n+1. Fill this array in with a O(n) loop over the array, and then go over the Boolean array and find the first false value, that index will be your mex.
u can simply use lower bound on the array instead of iterating all over. With a complexity of O(logn) insetad of O(n).
lower_bound
won't work because the array will not be of the form[1,1,1, 0, 0, 0, ...]
it can be something like[1, 0, 1, 1, 1, 1, 1]
Oh yeah u are right :)) Thats why i am newbie.
If there are $$$Q$$$ mex queries of ranges in an array lengthened $$$N$$$, then it can be solved in $$$O(Q\sqrt N+N)$$$ with Mo's algorithm.
in case of the given array is sorted, you can binary search on the first index that is not equal to it's value in the array, the answer will be that index. time
O(logN)
.Besides being sorted, the array should only have unique values.
this can be easily handled while taking the initial array.
If you want to just find out the mex of the whole array, write a simple loop.
If you want to query the mex of an interval for many times, this problem may help. https://www.luogu.com.cn/problem/P4137
Sorry I don't know "可持久化线段树"'s English translation.
It is a persistent segment tree.
Construct a hash array. Use Binary search and range query data structure such as minimum Sparse Table, check if in given range the minimum value is zero and accordingly update pointers.