zoukankan      html  css  js  c++  java
  • Luogu3740 [HAOI2014]贴海报 (线段树)

    倒着来

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 1007;
    
    struct Post{
    	int l, r;
    }a[N];
    
    int flag;
    int t[40000003];
    #define lson rt << 1, l, mid
    #define rson rt << 1 | 1, mid + 1, r
    inline void Pushup(int rt){
    	t[rt] = t[rt << 1] && t[rt << 1 | 1];
    }
    inline void Updata(int rt, int l, int r, int L, int R){
    	if(t[rt]) return;
    	if(L <= l && r <= R){
    		t[rt] = 1;
    		flag = 1;
    		return;
    	}
    	int mid = (l + r) >> 1;
    	if(L <= mid)
    		Updata(lson, L, R);
    	if(R > mid)
    		Updata(rson, L, R);
    	Pushup(rt);
    }
    
    int main(){
    	int LEN ,n;
    	io >> LEN >> n;
    	R(i,1,n){
    		io >> a[i].l >> a[i].r;
    	}
    
    	int ans = 0;
    	nR(i,n,1){
    		flag = 0;
    		Updata(1, 1, LEN, a[i].l, a[i].r);
    		ans += flag;
    	}
    	
    	printf("%d", ans);
    	
    	return 0;
    }
    

  • 相关阅读:
    QPS 与 TPS 简介
    程序员需要学多门语言吗
    Docker 常用命令
    Dockerfile
    Docker-安装与部署
    Docker 容器相关技术
    java多线程 线程八锁
    java多线程 生产者消费者案例-虚假唤醒
    ConcurrentHashMap
    原子变量与CAS算法
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11232577.html
Copyright © 2011-2022 走看看