Блог пользователя YosiefAhmed

Автор YosiefAhmed, история, 4 года назад, По-английски

Given array with n elements unique values, q query’s two type:

1: change the value of the element to other value which unique(not appear in array).

2: find the minimum value > 1 which not divisible by any other value in arrays

Can any one help me to solve this problem ?

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
4 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

not divisible by any number = the minimum prime number that does not appear in the array which is to get the mex of the prime numbers so you can ignore any non-prime number and only consider prime numbers and you can map each prime to its corresponding value .eg 2 -> 1, 3 ->2, 5 -> 3 and so on after that you can have a frequency array and a set and get the mex in O(logn).

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Since the elements are unique, you just need to find the minimum value in the array each time after performing the update operation. If the minimum value turns out to be 1 then there would be no answer for that case since you mentioned it must be greater than 1, otherwise the answer would be that minimum value only, since it is minimum it won't be divisible by any other value in the array.