码迷,mamicode.com
首页 > 其他好文 > 详细

bzoj1651:线段树+打标记

时间:2015-11-27 21:57:05      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

好吧我不知道究竟怎么了,明明自己测的数据能过,不理了。是因为没有先建树的原因然后哪里死了?草。。。以后再来。。明明道水题。

--------------------------------------------------------------------------------

#include<cstdio> 
#include<cstring> 
#include<iostream> 
#include<algorithm> 
using namespace std; 
#define rep(i,n) for(int i=1;i<=n;i++) 
#define clr(x,c) memset(x,c,sizeof(x)) 
int read(){ 
    int x=0; 
    char c=getchar(); 
    while(!isdigit(c)){ 
        c=getchar(); 
    } 
    while(isdigit(c)){ 
        x=x*10+c-0; 
        c=getchar(); 
    } 
    return x; 
} 
int s,t,add[4000000],nmax[4000000]; 

void insert(int o,int l,int r){ 
    if(r>l) 
      nmax[o]=max(nmax[o*2],nmax[o*2+1]); 
    nmax[o]+=add[o]; 
} 

void update(int o,int l,int r){ 
    if(s<=l&&r<=t){ 
       add[o]+=1; 
    } 
    else{ 
        int m=l+(r-l)/2; 
        if(t<=m) 
          update(o*2,l,m); 
        else if(s>m) 
          update(o*2+1,m+1,r); 
        else{ 
            update(o*2,l,m); 
            update(o*2+1,m+1,r); 
        } 
    } 
    insert(o,l,r); 
      
} 
int main(){ 
    clr(nmax,0); 
    clr(add,0); 
    int n=read(); 
    rep(i,n){ 
        s=read(),t=read(); 
        update(1,1,1000000); 
    } 
    printf("%d\n",nmax[1]); 
    return 0; 
}

 

--------------------------------------------------------------------------------

bzoj1651:线段树+打标记

标签:

原文地址:http://www.cnblogs.com/fighting-to-the-end/p/5001777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!