Finding the mistake in sorting vector of objects

Правка en1, от VandanRogheliya, 2020-07-15 11:49:08

I was solving D-Query question from SPOJ.

This was my original solution using an offline approach. Strangely for queries, more than 16 this program gave a segmentation fault

I modified the program according to one editorial to this and got AC

Note: Both programs only differ in sorting comp_ends function:

In 1st approach

int comp_ends(const Info& a, const Info& b) {
  if (a.type == b.type) {
    if (a.type == Q) return a.r <= b.r;
    return a.i <= b.i;
  } else {
    if (a.type == Q) return a.r < b.i;
    return a.i <= b.r;
  }
}

In 2nd approach

int comp_ends(const Info& a, const Info& b) {
  if (a.end < b.end) return true;
  else if (a.end == b.end) return a.type == I;
  else return false;
}

It will be very helpful if someone pointed out my mistake.

Thanks!

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский VandanRogheliya 2020-07-15 11:49:08 998 Initial revision (published)