• CF1278D Segment Tree(set+并查集)


    // Problem: CF1278D Segment Tree
    // Contest: Luogu
    // URL: https://www.luogu.com.cn/problem/CF1278D
    // Memory Limit: 250 MB
    // Time Limit: 2000 ms
    // Author:Cutele
    // 
    // Powered by CP Editor (https://cpeditor.org)
    
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll>PLL;
    typedef pair<int, int>PII;
    typedef pair<double, double>PDD;
    #define I_int ll
    inline ll read()
    {
        ll x = 0, f = 1;
        char ch = getchar();
        while(ch < '0' || ch > '9')
        {
            if(ch == '-')f = -1;
            ch = getchar();
        }
        while(ch >= '0' && ch <= '9')
        {
            x = x * 10 + ch - '0';
            ch = getchar();
        }
        return x * f;
    }
      
    inline void out(ll x){
        if (x < 0) x = ~x + 1, putchar('-');
        if (x > 9) out(x / 10);
        putchar(x % 10 + '0');
    }
      
    inline void write(ll x){
        if (x < 0) x = ~x + 1, putchar('-');
        if (x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
      
    #define read read()
    #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define repp(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>=(b);i--)
    #define perr(i,a,b) for(int i=(a);i>(b);i--)
    ll ksm(ll a, ll b,ll p)
    {
        ll res = 1;
        while(b)
        {
            if(b & 1)res = res * a%p;
            a = a * a %p;
            b >>= 1;
        }
        return res;
    }
    
    const int inf = 0x3f3f3f3f;
    const int maxn=5e5+7;
    
    int root[maxn];
    struct node{
    	int l,r;
    	bool operator < (const node & A) const{
    		return l < A.l;
    	}
    }a[maxn];
    
    
    
    int Find(int x){
    	if(x!=root[x]) root[x]=Find(root[x]);
    	return root[x];
    }
    set<node>s;
    int main(){
    	int n=read;
    	rep(i,1,n){
    		a[i].l=read,a[i].r=read;root[i]=i;
    	}
    	sort(a+1,a+n+1);
    	s.insert({a[1].r,1});
    	rep(i,2,n){
    		while(s.size()){
    			node t=*s.begin();
    			if(t.l<=a[i].l) s.erase(s.begin());
    			else break;
    		}
    		for(set<node>::iterator it=s.begin();it!=s.end();it++){
    			node t=*it;
    			if(t.l<a[i].r){
    				int u=i,v=t.r;
    				int fu=Find(u),fv=Find(v);
    				if(fu!=fv) root[fu]=fv;
    				else{
    					puts("NO");return 0;
    				}
    			}
    			else break;
    		}
    		s.insert({a[i].r,i});
    	}
    	int res=0;
    	for(int i=1;i<=n;i++)
    		if(i==Find(i)) res++;
    	if(res==1) puts("YES");
    	else puts("NO");
    	return 0;
    }
    
    
    
  • 相关阅读:
    小水滴
    “星际穿越”观后感(宇宙只是界面,科技永远触摸不到世界的本原)
    惊涛怪浪(double dam-break) -- position based fluids
    [转]Data Structure Recovery using PIN and PyGraphviz
    [转]Adventures in Xen exploitation
    [转]iOS Tutorial – Dumping the Application Memory Part 2
    [转] Building xnu for OS X 10.10 Yosemite
    [转]iOS Tutorial – Dumping the Application Heap from Memory
    [转]Even when one byte matters
    [转]iOS IPC via NSFileCoordinator and NSFilePresenter
  • 原文地址:https://www.cnblogs.com/OvOq/p/15096411.html
Copyright © 2020-2023  润新知