线段树(单点修改,区间查询)

#include<cstdio>

#include<iostream>

#include<cstring>

#include<set>

#include<map>

#include<cmath>

#include<cstdlib>

#include<algorithm>

#include<queue>

using namespace std;

int n,m;

int k=10005;

struct Node{

       int q;

}tree[4*k];

int a,b,t;

void xg(int l,int r,int root){

if(r<a || l>a)    return;
    if(r==l)
    {
        tree[root].p=b;
        return;

    }

}

int ss(int l,int r,int root)
{
    if(l>b || r<a)    return(-999999999);
 
    if(l>=a && r<=b)    return(tree[root].p);
 
    int mid=(l+r)/2;
    return(max( ss(l,mid,root*2), ss(mid+1,r,root*2+1)));
}

    int mid=(l+r)/2;
    xg(l,mid,root*2);
    xg(mid+1,r,root*2+1);

    tree[root].p=max(tree[root*2].p,tree[root*2+1].p);

}

int main(){

     freopen("2.in","r",stdin);

     freopen("2.out","w",stdout);

     memset(tree,0,sizeof(tree));

     scanf("%d",&n);

     for(int i=1;i<=n;i++){

           scanf("%d%d%d",&t,&a,&b);

          if(t==1)    xg(1,n,1);

          if(t==2)  printf("%d\n",ss(1,n,1));

}

     return 0;

}

猜你喜欢

转载自blog.csdn.net/wcy2003/article/details/80900901