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

Автор arjun_9426, история, 6 лет назад, По-английски

hello friend, i suffer a lot because of comparison functions and classes for sorting and STL data structures please help me in clearing this

comparison functions ex-> (1).when i try to sort using comparison function like->https://ideone.com/owtUzJ here problem comes when i try to sort according to my wish (2). sometimes even vectors of simple numbers give TLE or runtime error when i try to sort them using comparision function eg->https://ideone.com/FhzWw2

classes and structs https://ideone.com/FhzWw2 in this case it reinsert the value???

https://ideone.com/0POMaG in this case it reinsert the key value pair instead of just updating it???

https://ideone.com/Ae2DMR(another example where entry repeats)

please help me in this, i have suffered a lot because of this, recent one is (1)https://codeforces.me/contest/1082/submission/47244078(runtime error) (2)https://codeforces.me/contest/1082/submission/47244104(accepted) both codes are exactly same, i have just managed the comparison function benefits through extra code in 2nd one.

please somebody tell if there is any other way to use these functions/structs more effectively, else what and how we can use them . please somebody help

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

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

Your compare functions need to follow string weak ordering. To sort in reverse you should use a > b and not a >= b.

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

    thank sir, if in map/set if the compared item becomes equals what happens then(according to my verification it is leaving the other one from set/map) do i need to tell specifically when i need those entries?

    eg-> return a>b (it return false when a==b or a<b but both cases behaves different , in first it leave the second one, in second it considers and do swap)