hdu 4614 线段树+二分~

hdu4614 Vases and Flowers(简单线段树 + 二分) Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1336    Accepted Submission(s): 532 Problem Description   Alice i 阅读详情

Vases and Flowers

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 728    Accepted Submission(s): 251


Problem Description
  Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N-1. When she receive some flowers, she will try to put them in the vases, one flower in one vase. She randomly choose the vase A and try to put a flower in the vase. If the there is no flower in the vase, she will put a flower in it, otherwise she skip this vase. And then she will try put in the vase A+1, A+2, ..., N-1, until there is no flower left or she has tried the vase N-1. The left flowers will be discarded. Of course, sometimes she will clean the vases. Because there are too many vases, she randomly choose to clean the vases numbered 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 is the number of vases, and M is the operations of Alice. Each of the next M lines contains three integers. The first integer of one line is K(1 or 2). If K is 1, then two integers A and F follow. It means Alice receive F flowers and try to put a flower in the vase A first. If K is 2, then two integers A and B follow. It means the owner would like to clean the vases numbered from A to B(A <= B).
 

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 any one.'. For each operation of which K is 2, output the number of discarded flowers. 
   Output one blank line after each test case.
 

Sample Input
  
2 10 5 1 3 5 2 4 5 1 1 8 2 3 6 1 8 8 10 6 1 2 5 2 3 4 1 0 8 2 2 5 1 4 4 1 2 3
 

Sample Output
  
[pre]3 7 2 1 9 4 Can not put any one. 2 6 2 0 9 4 4 5 2 3 [/pre]
 

Source
 

Recommend
zhuyuanchen520
 
刚学线段树,做出来不容易啊~~~
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 50005;
struct node
{
    int l,r;
    int sum;
    int flag;
    int mid()
    {
        return (l+r)>>1;
    }
};
node tree[MAXN*4];
inline void pushup(int pos)
{
    tree[pos].sum=tree[pos<<1].sum+tree[pos<<1|1].sum;
}
inline void pushdown(int pos)
{
    if(tree[pos].flag==1)
    {
        tree[pos<<1].flag=1;
        tree[pos<<1|1].flag=1;
        tree[pos<<1].sum=0;
        tree[pos<<1|1].sum=0;
        tree[pos].flag=-1;
    }
    else if(tree[pos].flag==0)
    {
        tree[pos<<1].flag=0;
        tree[pos<<1|1].flag=0;
        tree[pos<<1].sum=tree[pos<<1].r-tree[pos<<1].l+1;
        tree[pos<<1|1].sum=tree[pos<<1|1].r-tree[pos<<1|1].l+1;
        tree[pos].flag=-1;
    }
}
void build(int l,int r,int pos)
{
    tree[pos].l=l;
    tree[pos].r=r;
    if(l==r)
    {
        tree[pos].sum=1;
        tree[pos].flag=-1;
        return ;
    }
    int mid=tree[pos].mid();
    build(l,mid,pos<<1);
    build(mid+1,r,pos<<1|1);
    pushup(pos);
    tree[pos].flag=-1;
}

int query(int l,int r,int pos)
{
    if(tree[pos].flag==1)
        return 0;
    else if(tree[pos].flag==0)
        return r-l+1;
    if(l==tree[pos].l&&tree[pos].r==r)
    {
        return tree[pos].sum;
    }
    int mid=tree[pos].mid();
    if(r<=mid)
        return query(l,r,pos<<1);
    else if(l>mid)
        return query(l,r,pos<<1|1);
    else
        return query(l,mid,pos<<1)+query(mid+1,r,pos<<1|1);
}
void update(int l,int r,int x,int pos)
{
    if(tree[pos].l==l&&tree[pos].r==r)
    {
        tree[pos].flag=x;
        if(x==0)
            tree[pos].sum=r-l+1;
        else
            tree[pos].sum=0;
        return ;
    }
    pushdown(pos);
    int mid=tree[pos].mid();
    if(r<=mid)
        update(l,r,x,pos<<1);
    else if(l>mid)
        update(l,r,x,pos<<1|1);
    else
    {
        update(l,mid,x,pos<<1);
        update(mid+1,r,x,pos<<1|1);
    }
    pushup(pos);
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        build(1,n,1);
        int i;
        for(i=0;i<m;i++)
        {
            int k,a,b;
            scanf("%d%d%d",&k,&a,&b);
            a++;
            if(k==2)
                b++;
            if(k==2)
            {
                int x=query(a,b,1);
                update(a,b,0,1);
                printf("%d\n",b-a+1-x);
            }
            else
            {
                int l=a,r=n;
                int x=query(l,r,1);
                //printf("asdf %d\n",x);
                if(x==0)
                {
                    printf("Can not put any one.\n");
                    continue;
                }
                int m1,m2;
                while(l<=r)
                {
                    int mid=(l+r)>>1;
                    x=query(a,mid,1);
                    if(x>0)
                    {
                        m1=mid;
                        r=mid-1;
                    }
                    else
                        l=mid+1;
                }
                l=a;r=n;
                x=query(l,r,1);
                m2=n;
                if(x<b)
                    b=x;
                while(l<=r)
                {
                    int mid=(l+r)>>1;
                    x=query(a,mid,1);
                    if(x>=b)
                    {
                        m2=mid;
                        r=mid-1;
                    }
                    else
                        l=mid+1;
                }

                update(m1,m2,1,1);
                printf("%d %d\n",m1-1,m2-1);
            }
        }
        printf("\n");
    }
    return 0;
}


灰色预测GM(1,n)模型_python 灰色系统理论及其应用系列博文: 一、灰色关联度分析法(GRA)_python 二、灰色预测模型GM(1,1) 文章目录一、GM(1,n)算法二、示例2.1 数据:2.2 代码_使用GM(1,n)城市用水总量2.3 结果分析 一、GM(1,n)算法 二、示例 注:数据均来自论文《基于灰色系统理论的贵阳市城市用水总量预测》 2.1 数据: data.csv 年份,城区人口,建成区面积,供水总量,用水人口,人口综合用水指标,城市用水总量 2002, 191.85, 98.00, 26396.00, 阅读详情

相关推荐

[STM32H750]HAL库下FMC驱动正点原子MCU屏的移植与优化

本文详细介绍了在STM32H750平台上使用HAL库移植与优化正点原子MCU屏幕驱动的完整过程。重点解析了FMC硬件配置、Cache一致性处理、精确延时实现等关键技术难点,提供了实用的移植方案和性能优化技巧,帮助开发者高效解决屏幕显示问题。

rock5的博客 286

hdu4614 : Vases and Flowers

线段树

weixin_46266058的博客 554

告别版本冲突!在Ubuntu 20.04上优雅实现ROS Noetic与ROS2 Foxy双环境切换

本文详细介绍了在Ubuntu 20.04系统上实现ROS Noetic(ROS1)与ROS2 Foxy双环境共存与切换的完整方案。通过智能脚本设计和工作空间隔离,解决了版本冲突问题,帮助开发者高效管理不同ROS版本项目。特别适合需要同时开发ROS1和ROS2应用的机器人开发者。

weixin_28452161的博客 411

hdu4614——线段树+二分

题目链接:https://vjudge.net/problem/HDU-4614#author=2013551629 Description Alice有N个花瓶(标号为0~ N-1)。当她收到一些花时,她会随机的选择一个瓶子A,从它开始遍历A,A+1, A+2, ..., N-1号瓶子,遇到空瓶子就放一朵花进去,直到花朵放完或没有瓶子,剩下的花将被丢弃。有...

mumei的博客 1349

安卓无障碍服务保活实战:如何用AccessibilityService实现后台常驻(附完整代码)

本文深入解析如何利用Android无障碍服务(AccessibilityService)实现后台服务保活,涵盖多版本系统适配、前台服务集成、开机自启机制等关键技术。通过详细的Kotlin代码示例和合规性指导,帮助开发者构建稳定可靠的后台服务解决方案,同时避免因滥用无障碍服务导致的应用下架风险。

milk5的博客 1073

产品需求从场景,初始需求IR,产品需求 OR,设计需求DR,设计规格DS的具体案例说明,以扫地机产品为例

摘要: 以扫地机器人"宠物粪便避障"功能为例,说明从用户场景到产品落地的完整需求转化路径。初始需求(IR)源于养宠家庭痛点,要求100%避障并自动告警;产品需求(OR)转化为≥98%识别准确率等量化指标;设计需求(DR)拆解为感知、决策、执行三大技术模块;最终形成传感器选型(如索尼IMX678)、芯片规格(高通QCS6490)等设计规格(DS)。通过实验室模拟和用户测试验证,该功能使产品溢价30%,养宠家庭购买占比达52%,实现技术与商业价值的统一。

AIoT深度探索者 | 嵌入式系统架构师 深耕物联网(IoT)与人工智能(AI)融合技术,聚焦​​边缘计算、图像开发、低功耗通信协议​​,致力于智能硬件,关注我获取最新技术文章信息与海量资源~ 771

HDU - 4614(线段树+二分查找)

题目意思:每一组的第一行有两个数n,m, n表示花瓶数量0~n-1,开始全为空,接下来有m组,每组有数k,a,b;当k=1时, 从a位置开始插花,b为花数量,当花瓶有花时,跳过当前,直到找到空花瓶再插入,输出插入第一支花的位置和最后一支花的位置,花可以没插完,当一支都没有插入则输出Can not put anyone.;当k=2时,清空【a,b】的花瓶,并输出在范围内花的数量。 代码: #incl...

qq_41856950的博客 263

【Proteus仿真】基于74LS148+74LS279+74LS48的四路抢答器

【Proteus仿真】基于74LS148+74LS279+74LS48的四路抢答器

perseverance51博客 8834

HDU - 4614 (线段树)

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 5e4 + 5; struct node { int sum, lazy; }tr[N << 2]; int t, n, m, k, x, y; void pushu...

ChenXiLian_的博客 395

SAPGUI excel 导出时遇到的运行时错误:STRING_SIZE_TOO_LARGE

当报表导出需求远超单一 XLSX 文件的物理承载力时,与其在 SAPGUI 中硬拼 2 GB 限制,不如把分页、过滤、流式写入作为设计前提。掌握 ABAP2XLSX 或 CSV + Power Query 等工具链,既能满足审计合规,又能让应用服务器远离的噩梦。祝你在下一次导出海量数据时,既高效又优雅。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 642

【人工智能时代】- 一键部署本地AI大模型

Ollama是一个开源项目,致力于简化大型语言模型(LLM)的本地部署过程。它允许用户在自己的硬件上运行和测试最新的语言模型,无需依赖云服务。Ollama提供了一个类似于OpenAI的API接口,使得开发者可以轻松地在自己的应用程序中集成大型语言模型。此外,Ollama WebUI为用户提供了一个友好的界面,用于管理和与模型进行交互。

xiaoli8748的专栏 2393

Vases and Flowers(线段树+二分)

Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N-1. When she receive some flowers, she will try to put them in the vases, one flower in one vase. S...

Steve·Curcy 638

LLM Wiki 的完整输入体系:LLM Wiki极简实战

LLM Wiki 的输入分为**四大类**,覆盖从"原始知识注入"到"系统行为控制"的全流程,所有输入都遵循"**原始资料不可变,规则可迭代,人类反馈闭环**"的核心原则。

ZhangJiqun&191cm&85kg 322

hdu4614 线段树+二分

/* hdu4614 线段树裸题 题意 有n个花瓶,两种操作: 1 L R 表示有R朵花,从L开始放,如果遇到有花的瓶子就跳过知道n这个瓶子,输出放花的起始点的花瓶下标 2 L R 表示清空L~R这之间的花瓶中的花,输出有多少支花被扔掉 1、花瓶下标是从0~n-1 2、把空瓶记为1,有花的瓶子记为0 线段树维护区间和,这样就可以直接得出区间空瓶树,然后二分查找出放花的起始点花瓶下标...

甦萌的博客 363

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU-4614 Vases and Flowers(线段树+区间修改+二分)

题目链接:\quadHDU - 4614题目大意:\quad有nn个花瓶,标号00 ~ n−1。m n - 1。m个操作, ‘1AF′\quad \quad ‘1 \quad A \quad F’,表示从AA位置开始插FF朵花,遇到有花的花瓶跳过。到最后一个花瓶都还有花剩余,丢弃剩下的花。 ‘2AB′\quad \quad ‘2 \quad A \quad B’,表示将区间[A,B][A, B

XzzF1024的博客 1263

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

hdu4614 Vases and Flowers 二分

hdu4614 Vases and Flowers 二分 这道题用数据结构为优化时间效率 用二分来分别找出左边界答案 和右边界答案 这是属于线段树数据结构与其他算法的结合使用 开始做的时候 还死死的在线段树上做文章。。。。 问题是 在以A为起点的区间 第一个可以插花的 和最后一个可以插花的地方 按照正常思路的话可以想到二分 可是与线段树扯上了 就只能想到在线段树上处理 看来这种结合思想

liyanfeng1996的博客 361

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

hdu4614 线段树区间覆盖和区间查询

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4614 Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 5201Accepted Subm...

Source_Roc 665

2013 多校第二场 hdu 4614 Vases and Flowers(线段树)

hdu 4614 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题目大意:n个花瓶,m个操作,k=1 时是从 a 开始插花,如果已经有花,那么跳过,能插多少插多少。k=2,把区间[ a , b ] 内的有的花都清理掉。 思路:裸线段树。就是找区间的时候比较麻烦,其实写两个二分先判断出左右边界就好了。。 时间是 2s ,再乘个 logn 应

沉溺的专栏 1096

HDU 4614

/* HDU 4614 Vases and Flowers 二分 + 线段树 */ #include #include #include using namespace std; #define lson (pos<<1) #define rson (pos<<1|1) const int maxn = 55555; int n,m,pos_x,pos_y; struct Node{ in

花月阁 520

HDU4614 Vases and Flowers(线段树+二分)

给出一些花瓶,有两种操作,1.从x位置向后插入y朵花,遇见已经有的就跳过,直到最后一个花瓶为止,输出第一和最后一个花瓶的位置,2.将x和y之间的花瓶清空输出花数。 线段树的写法差不多一致,关键是用二分来确定每次查询的左右端点。 #include #include #include using namespace std; const int N=500005; struct node {

HOrchard 377

Vases and Flowers (HDU - 4614,线段树 + 二分 + 思维)

一.题目链接: HDU-4614 二.题目大意: 有 N个花盆,起初都没有花. 1 个花盆只能插 1 朵花. 有 m 次 2 种操作. ① 1 A F:从第 A 花盆开始插 F 朵花,多余的丢弃. 若一朵花都无法插入,则输出 "Can not put any one." 否则,输出插花的起点、终点. ② 2 A B:将 A ~ B 花盆中的花丢弃,并输出所丢弃的花的个数. 三...

The___Flash的博客 374

HDU 4614 线段树+二分查找

Vases and Flowers 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4614 Problem Description   Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N-1. When...

weixin_30404405的博客 235

hdu 4614 线段树+二分

题目 这题我们的线段树储存的是区间内空的树有几个,这样就很好做了。如果区间内没有空的那肯定输出那个字符串,然后二分去找k=1的l和r,k=2就用区间长度减去区间询问就好了,其实也不难。 #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<vector> #include<cmath> #include<map>

qq_37073764的博客 841

hdu 4614 Vases and Flowers(线段树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4614 题意: 给你N个花瓶,编号是0 到 N - 1 ,初始状态花瓶是空的,每个花瓶最多插一朵花。 然后有2个操作。 1)a b 往在a位置后面(包括a)插b朵花,输出插入的首位置和末位置。 2)a b 输出区间[a , b ]范围内的花的数量,然后全部清空。 操作看起来挺简单...

awow80285的博客 122

HDU-4614-Vases and Flowers(线段树)

题目链接:HDU-4614-Vases and Flowers 题意是有n个花瓶在一个线段上,用0~n-1来标记,有两种操作,第一种是从x开始插花,一直向后插y个花,如果一个花瓶里已经插有花,则不能再插,求第一个插花的位置和最后一个插花的位置,如果一朵花都插不了的话,输出"Can not put any one"。第二种操作是将x到y花瓶里的花拿出来,并输出拿出来的花数。 很...

abcd12341abcd1234的博客 205

HDU 4614 线段树+二分

一开始做用自己的方法,一直WA,自己也出不出错误的例子,放弃了自己的代码,看了一下别人的方法都是线段树+二分,逻辑很清晰,也很好写,基本就是板子。 #include #include #include #include using namespace std; struct node { int sum,lz; }a[50005 << 3]; void build(int d,

可以说非常弱鸡 371
上一篇: hdu 4607 求树的直径
下一篇: hdu 3577 线段树,成段更新
JustSteps
博客等级 码龄14年 48粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值