题意:有两种操作,第一种从A开始插花,如果有花就跳到下一个,然后输出最后一个花瓶的编号,如果花瓶不够把多余的花丢掉。操作2把区间清空
分析:很明显的线段树操作,就是插花的时候麻烦一下,需要先找出来他剩余的花瓶数,要不没办法更新。
*******************************************************************
#include<algorithm>
#include<stdio.h>
using namespace std; #define lson r<<1
#define rson r<<1|1 const int MAXN = 1e5+; struct stgmentTree
{//sum花瓶的剩余量
    int x, y, sum, cover;//cover, 操作1赋值为释放花瓶,操作2沾满花瓶
    int mid(){return (x+y)>>;}
    int len(){return y-x+;}
}a[MAXN<<];
int ans;
void Build(int r, int x, int y)
{
    a[r].x = x, a[r].y = y;
    a[r].sum = a[r].len(), a[r].cover = ;     if(x == y)
        return ;     Build(lson, x, a[r].mid());
    Build(rson, a[r].mid()+, y);
}
void Down(int r)
{
    if(a[r].x != a[r].y && a[r].cover)
    {
        a[lson].cover = a[rson].cover = a[r].cover;
        a[lson].sum = a[r].cover== ?  : a[lson].len();
        a[rson].sum = a[r].cover== ?  : a[rson].len();         a[r].cover = ;
    }
}
void Insert(int r, int x, int y, int op)
{
    if(a[r].x == x && a[r].y == y)
    {
        ans += a[r].len()-a[r].sum;
        a[r].cover = op;
        a[r].sum = (op== ?  : a[r].len());         return ;
    }     Down(r);     if(y <= a[r].mid())
        Insert(lson, x, y, op);
    else if(x > a[r].mid())
        Insert(rson, x, y, op);
    else
    {
        Insert(lson, x, a[r].mid(), op);
        Insert(rson, a[r].mid()+, y, op);
    }     a[r].sum  = a[rson].sum + a[lson].sum;
}
int QueryPreSum(int r, int k)//求k前面的空花瓶数
{
    Down(r);     if(a[r].x == a[r].y)
        return ;
    if(k <= a[r].mid())
        return QueryPreSum(lson, k);
    else
        return a[lson].sum + QueryPreSum(rson, k);
}
int QueryLast(int r, int p)//查找第p个花瓶位置
{
    Down(r);     if(a[r].x == a[r].y)
        return a[r].x;     if(a[lson].sum >= p)
        return QueryLast(lson, p);
    else
        return QueryLast(rson, p-a[lson].sum);
} int main()
{
    int T;     scanf("%d", &T);     while(T--)
    {
        int N, M, op, x, y, L, R;         scanf("%d%d", &N, &M);         Build(, , N-);         while(M--)
        {
            scanf("%d%d%d", &op, &x, &y);
            if(op == )
            {
                int PreSum = QueryPreSum(, x);                 if(PreSum == a[].sum)
                    printf("Can not put any one.\n");
                else
                {
                    L = QueryLast(, PreSum+);                     if(PreSum+y >= a[].sum)
                        PreSum = a[].sum;
                    else
                        PreSum += y;
                    R = QueryLast(, PreSum);                     Insert(, L, R, );                     printf("%d %d\n", L, R);
                }
            }
            else
            {
                ans = ;
                Insert(, x, y, );
                printf("%d\n", ans);
            }
        }         printf("\n");
    }     return ;
}
/*
2
10 8
1 2 5
2 3 4
1 0 8
2 2 5
1 6 1
1 4 4
1 2 3

*/

L - Vases and Flowers - hdu 4614(区间操作)的更多相关文章

  1. L - Vases and Flowers HDU - 4614 线段树+二分

    题意 给出一排空花瓶 有两种操作  1是 从A花瓶开始放F朵花 如果当前瓶有花就跳过前往下一个 直到花用完或者 瓶子到了最后一个为止 输出 成功放花的第一个和最后一个  如果没有输出 can not. ...

  2. HDU-4614 Vases and Flowers 线段树区间更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 线段树保存区间是否被覆盖以及区间的和即可,在询问的时候在线段树上二分查找就可以了...代码写得比 ...

  3. 【HDU 4614】Vases and Flowers(线段树区间更新懒惰标记)

    题目0到n-1的花瓶,操作1在下标a开始插b朵花,输出始末下标.操作2清空[a,b]的花瓶,求清除的花的数量.线段树懒惰标记来更新区间.操作1,先查询0到a-1有num个空瓶子,然后用线段树的性质,或 ...

  4. 2013 多校联合2 D Vases and Flowers (hdu 4614)

    Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others ...

  5. HDU 4614 Vases and Flowers(线段树+二分)

    Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others ...

  6. HDU 4614 Vases and Flowers (2013多校2 1004 线段树)

    Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others ...

  7. HDU-4614 Vases and Flowers(线段树区间更新+二分查找)

    http://acm.hdu.edu.cn/showproblem.php?pid=4614 Time Limit: 4000/2000 MS (Java/Others)    Memory Limi ...

  8. HDU 4578——Transformation——————【线段树区间操作、确定操作顺序】

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others)T ...

  9. HDU 1754 I Hate It (Splay 区间操作)

    题目大意 维护一个序列,支持两种操作 操作一:将第x个元素的值修改为y 操作二:询问区间[x,y]内的元素的最大值 解题分析 splay的区间操作,事先加入两个编号最小和最大的点防止操作越界. 具体的 ...

随机推荐

  1. ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number;

    rpm 安装了 mysql 5.6 的版本 遇到的问题 1. 提示与5.1版本的有冲突. 解决方式, 是 rpm --force -ivh rpm包.rpm 进行强制安装 2. 启动 mysql 后, ...

  2. python摇骰子猜大小的小游戏

    #小游戏,摇筛子押大小的小游戏玩家初始有1000块钱,可以压大压小作为赌注 import random #定义摇筛子的函数: def roll_dice(number = 3,points = Non ...

  3. 在/etc/password用户名前面加hello,ID前加is

    方法2: #!/bin/sh #set -x file=/etc/passwd while read LINE #for i in `cat $file` do #username=`echo $i| ...

  4. 解决Windows8前面板耳机无声的问题

    Windows8已经到来不久了,相信很多朋友已经在使用,在使用时也许会遇到前面板耳机无声的问题,网上的其他办法很麻烦还不一定能解决,在这里我会给大家提供最简单的办法解决这个问题. 百度经验:jingy ...

  5. PHP magic_quotes_gpc的详细使用方法

    工作中遇到的代码 if (ini_get('magic_quotes_gpc')) { function stripslashesRecursive(array $array){ foreach ($ ...

  6. this,super关键字的使用

    this关键字 1.this是对象的别名,是当前类的实例引用 2.在类的成员方法内部使用,代替当前类的实例.在Java中,本质上是指针,相当于C++中的指针概念.如果方法中的成员在调用前没有操作实例名 ...

  7. adb shell - device not found

    如果是真机,则连接usb即可(我的是真机).

  8. iOS关于sqlite3操作

    原文:http://hi.baidu.com/clickto/blog/item/0c6904f787c34125720eec87.html iPhone中支持通过sqlite3来访问iPhone本地 ...

  9. iOS: TableView如何刷新指定的cell 或section

    //一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2]; [tableview reloadSections:in ...

  10. Xshell下漂亮的开发环境配置

    今天折腾了一天Xshell配置Linux命令行开发环境. 总结几点: 1.Xshell配色方案,这是我自己调的个人使用版,网上比较好的版本有Solarized Dark,可以下载到. [ColorFo ...