UNICOLOR Runtime error

Can someone please look at my code and tell me why its giving Runtime error SIGSEGV.
I don’t think I’m using too much memory here for the subtask considering n is 1000.
Problem - CodeChef: Practical coding for everyone
Solution - CodeChef: Practical coding for everyone

#include <iostream>
#include<bits/stdc++.h>
#define ll long long 
#define int ll
#define pb push_back
#define pii pair<int,int>
#define f(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
using namespace std;

const ll mod = 998244353 ;
void solve(){
	ll c, n , m;
	cin >> c >> n >> m;
	
	vector<pair<int,int>> orig,seg;
	map<pii,int> mp;
	for(int i=1;i<=c;i++){
		
		int cl;
		cin >> cl;
		for(int j=1;j<=cl;j++){
			pair<int,int> p;
			cin >> p.first >> p.second;
			if(mp.find(p)==mp.end())
			orig.pb(p);
			
			mp[p]=1;
			
		}
	}
	
	sort(orig.begin(),orig.end(),[](pair<ll,ll> p1, pair<ll,ll>p2){
		
		if(p1.first <= p2.first){
			return true;
		}else return false;
			
	});
	
	
	int i=1;
	pair<int,int> p = make_pair(orig[0].first,orig[0].second);
	seg.pb(p);
	
	while(i<orig.size()){
		if(orig[i].first <= seg.back().second){
			seg.back().second = max(orig[i].second , seg.back().second);
			
		}
		else{
			
			seg.pb({orig[i].first,orig[i].second});
			
		}
		i++;
	}
	
	//cout << seg.size()<<endl;
	int vis[2000]{0};
	
	for(auto a : seg){
		for(int i=a.first;i<=a.second;i++){
			vis[i]=1;
		}
	}
	
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			seg.pb({i,i});
		}
	}
	
	ll sz = seg.size();
	cout << (m*sz)%mod<<endl;
	
	
	
	
	
}

signed main() {
		ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
	int t;
	cin >> t;
	
	while(t--)
	    solve();
	    
	return 0;
}

Thanks.

The comparison lambda you are using to sort with is non-conformant:

[simon@simon-laptop][17:14:41]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling vruttant1403-UNICOLOR.cpp
+ g++ -std=c++14 vruttant1403-UNICOLOR.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
vruttant1403-UNICOLOR.cpp: In function ‘void solve()’:
vruttant1403-UNICOLOR.cpp:46:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(i<orig.size()){
           ~^~~~~~~~~~~~
+ set +x
Successful
[simon@simon-laptop][17:14:54]
[~/devel/hackerrank/otherpeoples]>echo "1                 
2 6 3
2
1 2 5 6
1
4 6" | ./a.out
/usr/include/c++/7/bits/stl_algo.h:4866:
Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)).

Objects involved in the operation:
    instance "functor" @ 0x0x7ffcf2339b5b {
      type = solve()::{lambda(std::pair<long long, long long>, std::pair<long long, long long>)#1};
    }
    iterator::value_type "ordered type" {
      type = std::pair<long long, long long>;
    }
Aborted (core dumped)

It needs to implement a strict weak ordering.

Edit:

Here’s another handy link.

I can’t believe this lol. Changing from p1.first <= p2.first to p1.first < p2.first gave me 30 points :frowning: . Will keep the strict weak ordering in mind next time. Thanks a lot.
Can you tell me how did you compile this to check for this error? My compiler doesn’t show this as a warning too

1 Like

The command-line used to compile it is in my post (the line involving g++; ignore the + at the beginning of the line).

1 Like

Got it . Thanks a ton!

1 Like