Strange behavior of stl or not?

Revision en3, by RogueNinja, 2017-06-09 23:14:24

Today while solving this problem I faced a strange behavior with set<>.

I made three identical submissions only with slight changes in compare function to see it's behavior.

My three submission: 1. http://codeforces.me/contest/802/submission/27695695

verdict : AC

compare function :

bool operator < ( const data& b ) const {
    if(pos == b.pos)    {
        return num > b.num;
    }
   return pos < b.pos;
}
  1. http://codeforces.me/contest/802/submission/27695705

verdict : AC

compare function :

bool operator < ( const data& b ) const {
    if(pos == b.pos)    {
        return num < b.num;
    }
   return pos < b.pos;
}
  1. http://codeforces.me/contest/802/submission/27695712

verdict : WA

compare function :

bool operator < ( const data& b ) const {
   return pos < b.pos;
}

Now, it can be my fault but I always have used third option when I have to compare single variable and class contains multiple variables. Also, choosing this always worked out for me, but it's not the case this time.

Now, I want to know what's causing this and why using third option is wrong? Also, what I should do if I only want to compare single or multiple variables but not all variables?

Tags #set, #c++, stl

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English RogueNinja 2017-06-10 03:58:12 9
en6 English RogueNinja 2017-06-10 03:55:33 41 Tiny change: 'Today whil' -> '[SOLVED] .... Bug was in my code.....\n\nToday whil'
en5 English RogueNinja 2017-06-09 23:20:59 11 Tiny change: 'ssion:**\n1. http:' -> 'ssion:**\n\n1. http:'
en4 English RogueNinja 2017-06-09 23:17:02 0 (published)
en3 English RogueNinja 2017-06-09 23:14:24 12
en2 English RogueNinja 2017-06-09 23:13:38 2 Tiny change: 'h set<>.\nI made t' -> 'h set<>.\n\nI made t'
en1 English RogueNinja 2017-06-09 23:13:12 1353 Initial revision (saved to drafts)