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

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

Problem:- https://mirror.codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/C

My submission:-https://pastebin.com/GGeGnBdT or https://ideone.com/VNbvP0

It is giving WA on test case 14 again and again.

Plz can anyone tell where is bug in my code.Any help would be appreciated.

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

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

I guess your merge function is wrong. Instead you can store the indexes in a unordered map , where the key will be the number and values will be vector where that particular number is present in the array. And for updates u can easily update the vector. Using segment tree u can calculate the range minimum. after finding the minimum ,u can just use binary search to find the first and the last occurrence of the minimum in the vector in log(N) and the difference between their positions is the required answer. Hope u get it . U can refer my code for more clarity. solution link