hdu 4614線分樹区間カバーと区間クエリ


テーマリンク:
http://acm.hdu.edu.cn/showproblem.php?pid=4614
Vases and Flowers
Time Limit:4000/2000 MS(Java/Others)    メモリLimit:65535/32768 K(Java/Others)Total Submission(s):5201    Acceepted Submission(s):2159
 
Problem Description
アイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイアイower in it,the the the the the the she will tre will put in the vase A+1、A+2、…、N-1、until there isのflower lefr r she the vase N-1.The left flowers will will be discarded.Of course、someclclclclclcleesssssssclclclclclclclclclclclclclclclclclclclclclclclclclclclamamamamamamamamamshshshshshshshshshshshshshshshshshshshshshshshshshshshshe e e e e e e e e e e e e e e e e e e e e e e eベルドfrom A to B(A<=B).The flowers in the cleaned vases will be discarded.
   
Input
The first line contains an integer T、indicating the number of test cases.For each test case、the first line contains two integers N(1<N>50001)and M(1<M<50001).N isthe Alnumber of vases、the ininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininor 2).If K is 1、then two integers A and Fフォロワー.It means Alice receive F flowers and try to put a flower in the varst.If K is 2,then twotegers A and Bフォロワー.It means the owner would like to cleambers.from
   
Output
For each operation of which K is 1、output the position of the vase in which Alice put the first flower and last one、separated by a blank.If she can not put any one、then output'Can not put put put put Ony.Foarch of  Output one blank line after each test case.
   
Sample Input
 
2 10 5 1 3 5 2 4 1 1 1 8 3 6 1 8 8 1 8 1 2 5 2 3 4 1 0 8 2 2 2 5 5 1 2 2 5 1 2 5 1 4 1 2 2 4 1 2 3 3 3 3.
   
Sample Output
 
[pre]3 7 2 1 9 Can not put any one.2 2 0 9 4 4 5 3[/pre]
   
Author
SYSU
   
ソurce
2013 Multi-University Training Conteest 2
   
Recommund
zhuyuanchen 520
   
Sttistic | Submit | ディスク | ノート
タイトルの大意:
n個の花瓶、m個の操作で、花瓶の中には花があります。最初は全部空です。
1操作はaから右にbの花を置いて、花瓶があったら置かないで、aの右に花がいっぱい置いてあるまで飛ばして、余分に投げました。今回花を入れる開始位置を出力します。一輪が入れられないなら、一言を出力してください。
2操作は区間[a,b]をクリアする花です。出力はどれぐらいの花をクリアしましたか?
考え方:
線分樹、1は花がないことを表して、0は花があることを表して、区間は更新を覆って、区間と引き分けを求めます。
二分で生け花を始める場所と最終生け花の場所を探します。
This the code
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define PI acos(-1.0)
#define pppp cout<='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
const int MAXN=50005;
int sum[MAXN<<2];
int up[MAXN<<2];

void push_up(int i)
{
    sum[i]=sum[i<<1]+sum[i<<1|1];
}

void push_down(int i,int l,int r)
{
    if(up[i]!=-1)
    {
        int mid=(l+r)>>1;
        sum[i<<1]=up[i]*(mid-l+1);
        sum[i<<1|1]=up[i]*(r-mid);
        up[i<<1]=up[i];
        up[i<<1|1]=up[i];
        up[i]=-1;
    }
}

void build(int i,int l,int r)
{
    up[i]=-1;
    if(l==r)
    {
        sum[i]=1;
        return ;
    }
    int mid=(l+r)>>1;
    build(i<<1,l,mid);
    build(i<<1|1,mid+1,r);
    push_up(i);
}

void update(int i,int l,int r,int x,int y,int val)
{
    if(x<=l&&r<=y)
    {
        sum[i]=val*(r-l+1);
        up[i]=val;
        return ;
    }
    push_down(i,l,r);
    int mid=(l+r)>>1;
    if(x<=mid)
        update(i<<1,l,mid,x,y,val);
    if(y>mid)
        update(i<<1|1,mid+1,r,x,y,val);
    push_up(i);
}

int query(int i,int l,int r,int x,int y)//            
{
    if(x<=l&&r<=y)
        return sum[i];
    push_down(i,l,r);
    int mid=(l+r)>>1;
    int sum=0;
    if(x<=mid)
        sum+=query(i<<1,l,mid,x,y);
    if(y>mid)
        sum+=query(i<<1|1,mid+1,r,x,y);
    return sum;
}
int main()
{
    //freopen("D:\\chnegxubianji\\inORout\\in.txt", "r", stdin);
    //freopen("D:\\chnegxubianji\\inORout\\out.txt", "w", stdout);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        build(1,0,n-1);//  
        while(m--)
        {
            int tem,x,y;
            scanf("%d%d%d",&tem,&x,&y);
            if(tem==1)
            {
                int num=query(1,0,n-1,x,n-1);
                if(num==0)
                {
                    printf("Can not put any one.
"); continue; } if(num>1; if(query(1,0,n-1,x,mid)>=1) r=mid-1; else l=mid+1; } int ansl=l; l=x,r=n-1; while(l<=r) { int mid=(l+r)>>1; if(query(1,0,n-1,x,mid)>=y) r=mid-1; else l=mid+1; } int ansr=l; printf("%d %d
",ansl,ansr); update(1,0,n-1,ansl,ansr,0); } else { int num=query(1,0,n-1,x,y); printf("%d
",y-x+1-num); update(1,0,n-1,x,y,1); } } printf("
"); } return 0; }