Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Giant_on_weed's blog

By Giant_on_weed, history, 5 years ago, In English

I tried to make a set out of this struct and it gives compilation error

struct triplet{
    int first;
    int second;
    int index;
    bool operator < (const triplet &A){
        if(first==A.first)return second < A.second;
        return first < A.first;
    }
};

The operator works while simple sorting but is giving error while implementing sets, maps and priority_queues.

  • Vote: I like it
  • -3
  • Vote: I do not like it

»
5 years ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

Here

struct triplet{
    int first;
    int second;
    int index;
    bool operator < (const triplet &A) const {
        if(first==A.first)return second < A.second;
        return first < A.first;
    }
};

Operator can't change triplet. Otherwise it would be hard to balance BST :D