PARTY Using Bitwise

Revision en2, by Mohsina_Shaikh, 2022-08-23 05:17:28

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;
                 //setting bits from range l to r
                 for(int j=li;j<=ri;j++){
                     b1[j]=1;
                 }
            }
             int i=0;
             for(i=0;i<m;i++){
                 //iterating over all m pairs
                 //to find if haters pair is set
                 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

Tags bitset, c++, bitmap, #trending

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Mohsina_Shaikh 2022-08-23 05:17:28 148
en1 English Mohsina_Shaikh 2022-08-23 05:15:45 1310 Initial revision (published)