Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define dbg(i,j) cout<<"I am "<<i<<" = "<<endl<<j<<endl;
- #define dbr(name,a) cout<<name<<endl;for(auto x:a)cout<<x<<" ";cout<<endl;
- #define DBR(name,a) cout<<name<<endl;for(auto x:a){ for(auto y:x)cout<<y<<" ";cout<<endl;}
- #define dbmp(name,a) cout<<name<<endl;for(auto x:a){ cout<<x.first<<"\t"<<x.second<<endl;}
- #define dbp(name,a) cout<<name<<endl;cout<<a.first<<"\t"<<a.second<<endl;
- #define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- using namespace std;
- typedef long long int big;
- typedef long double fig;
- big mx(vector<big>& v,big i,big j){
- big m=i;
- for(big z=i+1;z<=j;z++){
- if(v[z]>v[m]){
- m=z;
- }
- }
- return m;
- }
- big mn(vector<big>& v,big i,big j){
- big m=i;
- for(big z=i+1;z<=j;z++){
- if(v[z]>v[m]){
- m=z;
- }
- }
- return m;
- }
- bool Find_Intersection(pair<big,big>& p1,pair<big,big>& p2){
- if(p2.first<=p1.second){
- p1.first=p2.first;
- p1.second=min(p1.second,p2.second);
- return true;
- }
- else{
- return false;
- }
- }
- int main(){
- big test;
- cin>>test;
- while(test--){
- big n;
- cin>>n;
- vector<pair<big,big>> pairs;
- for(big i=0;i<n;i++){
- big a;
- big b;
- cin>>a>>b;
- pairs.push_back(make_pair(a,b));
- }
- sort(pairs.begin(),pairs.end());
- big count=1;
- pair<big,big> test=pairs[0];
- for(big j=1;j<n;j++){
- if(Find_Intersection(test,pairs[j])){
- ;
- }
- else{
- count++;
- test=pairs[j];
- }
- }
- cout<<count<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment