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

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

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
  • Проголосовать: не нравится

»
13 месяцев назад, # |
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).

  • »
    »
    13 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Could you explain how to find mex in O(logn) and are we Mapping each prime number to the index of the array?

    • »
      »
      »
      13 месяцев назад, # ^ |
      Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

      there is no need for mapping or a frequency array I have just noticed that. you can have only a set that contains prime numbers that does not appear in the array. if a prime number is removed then add it to the set. if a prime number is added then remove it from the set. the answer will be the first element in the set(*st.begin())

»
13 месяцев назад, # |
  Проголосовать: нравится 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.