Madara__Uchiha__'s blog

By Madara__Uchiha__, history, 3 years ago, In English

Problem:- https://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.

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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