Hello can anyone please explain how to optimize this code.Currently It is giving TLE.
#include<bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
std::cin >> t;
while(t--)
{
int n,m,q;
cin>>n>>m;
vector<pair<int,int>> haters(m,make_pair(0,0));
int x=0,y=0;
for(int i=0;i<m;i++){
cin>>x>>y;
haters[i].first=x;
haters[i].second=y;
}
cin>>q;
int k=0,li=0,ri=0;
while(q--){
bitset<200005> b1;
cin>>k;
for(int i=0;i<k;i++){
cin>>li>>ri;
for(int j=li;j<=ri;j++){
b1[j]=1;
}
}
int i=0;
for(i=0;i<m;i++){
if(b1[haters[i].first]==1 && b1[haters[i].second]==1){
break;
}
}
if(i==m){
cout<<"YES"<<"\n";
}else{
cout<<"NO"<<"\n";
}
}
}
return 0;
}
Adding the Problem Link : PARTY Can anyone please help on how we can optimize this