Doubt with Maps, Sets with Custom Struct as Key

Revision en3, by dp_16, 2024-04-30 15:58:16

If we have struct like this:

struct Example{
    int first, second;
    bool operator<(const Example &another) const {
        if(first==another.first)return second>another.second;
        return first>another.first;
    }
}

In other words, struct which has two integer variables first, second. Same as standard pair<int, int> variable but is difference in how will it be sorted in some data structure (vector, map...)

Could there be increase in TC if we talk about sorting when inserting simpler variables inside of maps, sets etc.? (simple variables — where the code inside operator would be O(1). Like in the example).

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English dp_16 2024-04-30 16:00:55 6
en4 English dp_16 2024-04-30 15:59:13 1 Tiny change: '\n }\n}\n~~~~~\n\' -> '\n }\n};\n~~~~~\n\'
en3 English dp_16 2024-04-30 15:58:16 1
en2 English dp_16 2024-04-30 15:57:49 7
en1 English dp_16 2024-04-30 15:55:45 702 Initial revision (published)