HDU4027 - Can you answer these queries? (线段树)

fanuc机器人I/O分配 FANUC机器人在和其他外部设备进行通讯时,需要对信号进行配置。 在机器人处于UOP自动分配状态时,系统会自动检索已配对设备,并分配相应的机架号。 当我们需要手动对信号进行分配时,可参考以下机架号进行配置。 不同的通讯协议对应的机架号不同,外部通讯协议常用的机架号参考下表: 序号 机架号 通讯类型 1 0 Process I/O 2 1-15 阅读详情

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=4027


题目分析:

区间开根号下取整,询问区间和。


解题过程:

注意,进行更新和询问的操作的时候要注意 x 和y的大小,这里被坑了,差点以为自己清奇的脑洞不对……

发现好多人都是转化为单点更新,自己比较耿直,写了好长的区间更新代码,也算是一题多解吧。


题目分析:

单点更新解法:

首先要注意到对于开根号操作,这里的输入数据大小不会超过 264 要不就没法玩了,这样的话,对于每个数顶多开 64 次根号。

这样暴力进行单点更新最多也就 O(64×nlog(n)) ,加上剪枝就可以过,对于每个区间,如果这个区间内的所有数都为 1 ,那么这个区间开根号后区间和也没变化了,可以剪枝。

区间更新解法:

因为要进行区间更新,所以要用到lazy标记,但是用lazy标记要保证两个条件,一是标记可以叠加,二是打上标记后可以直接的更新区间维护的信息。

对于开根号操作,好像是不符合第二个条件,对于一个区间打上lazy标记后,不能直接计算出新的区间和。这里想到可以预处理前缀和,因为每个数最多也就开64次根号,预处理完对于开 1 到64次根号所有的前缀和,这里加下判断,如果所有数都为 1 的话,那么就不需要继续往下计算了。

有了前缀合,那么对于一段区间如果这段区间内所有数字开根号的次数都相同,那么我就可以用前缀和计算出区间和了。所以当一段区间内所有数的开根号次数都一样的话,就可以打lazy标记了。

然后注意更新和合并区间的过程,更新有可能会使一段区间内开根号次数不同,或变得相同,合并区间时要处理一下。


AC代码:

单点更新:

#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;

#define lson root<<1
#define rson root<<1|1
#define MID int m = (l + r) / 2

typedef long long LL;

const int MAX = 112345;

struct Info {
    LL value;
}tree[MAX<<2];

LL data[MAX];

void build(int root, int l, int r) {
    if (l == r) {
        tree[root].value = data[l];
        return;
    }
    MID;
    build(lson, l, m);
    build(rson, m+1, r);
    tree[root].value = tree[lson].value + tree[rson].value;
}

void updata(int root, int l, int r, int ul, int ur) {
    if (r < ul || ur < l || tree[root].value <= (r-l+1))
        return;
    if (ul <= l && r <= ur && l == r) {
        tree[root].value = sqrt(tree[root].value);
        return;
    }
    MID;
    updata(lson, l, m, ul, ur);
    updata(rson, m+1, r, ul, ur);
    tree[root].value = tree[lson].value + tree[rson].value;
}

LL query(int root, int l, int r, int ul, int ur) {
    if (r < ul || ur < l)
        return 0;
    if (ul <= l && r <= ur) {
        return tree[root].value;
    }
    MID;
    return query(lson, l, m, ul, ur) + query(rson, m+1, r, ul, ur);
}

int main() {
    int n, m, cases = 0;
    while (~scanf("%d", &n)) {
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &data[i]);
        }
        build(1, 1, n);
        scanf("%d", &m);
        printf("Case #%d:\n", ++cases);
        while (m--) {
            int top, x, y;
            scanf("%d %d %d", &top, &x, &y);
            if (x > y)
                swap(x, y);
            if (top) {
                printf("%lld\n", query(1, 1, n, x, y));
            }
            else {
                updata(1, 1, n, x ,y);
            }
        }
        putchar('\n');
    }
}

区间更新:

#include<stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

#define lson root<<1
#define rson root<<1|1
#define MID int m = (l+r)/2

const int MAX = 112345;
typedef long long LL;

LL pre[64][MAX];

int times;

struct Info {
    int lazy, l, r, num;
    bool ok;
    LL value;
    Info() {
        lazy = l = r = ok = num = value = 0;
    }
    void maintain(int v) {
        num += v;
        //如果开根号大于times次,那么和开times次相同
        if (num > times)
            num = times;
        value = pre[num][r] - pre[num][l-1];
    }
}tree[MAX*4];

void push_down(int root) {
    if (tree[root].lazy) {
        int v = tree[root].lazy;
        tree[lson].lazy += v;
        tree[rson].lazy += v;
        //打完lazy标记后重新计算下区间和
        tree[lson].maintain(v);
        tree[rson].maintain(v);
        tree[root].lazy = 0;
    }
}

Info operator + (const Info & a, const Info & b) {
    Info rst;
    rst.l = a.l;
    rst.r = b.r;
    //如果左右儿子开根号次数相同,并且区间内所有元素开根号次数都相同,那么父节点区间内开根号次数都相同
    rst.ok = (a.num == b.num) && a.ok && b.ok;
    if (rst.ok) {
        rst.num = a.num;
        rst.maintain(0);
    }
    return rst;
}

void updata(int root, int l, int r, int ul, int ur) {
    //如果区间内所有元素都为1,那么可以跳过更新
    if(r-l+1==tree[root].value) return;
    //如果区间在更新的区间内,并且区间内所有元素开根号次数都相同,那么可以打lazy标记
    if (ul <= l && r <= ur && tree[root].ok) {
        tree[root].lazy += 1;
        tree[root].maintain(1);
        return;
    }
    MID;
    push_down(root);
    if (ul <= m) updata(lson, l, m, ul, ur);
    if (m+1 <= ur) updata(rson, m+1, r, ul, ur);

    tree[root] = tree[lson] + tree[rson];
}

void build(int root, int l, int r) {
    tree[root].l = l;
    tree[root].r = r;
    tree[root].value = 0;
    tree[root].lazy = 0;
    tree[root].ok = 1;
    tree[root].num = 0;
    if (l == r) {
        tree[root].maintain(0);
        return;
    }
    MID;
    build(lson, l, m);
    build(rson, m+1, r);
    tree[root].value = tree[lson].value + tree[rson].value;
}

LL query(int root, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr && tree[root].ok) {
        return tree[root].value;
    }
    MID;
    push_down(root);
    LL sum = 0;
    if (ql <= m) sum += query(lson, l, m, ql, qr);
    if (m+1 <= qr) sum += query(rson, m+1, r, ql, qr);
    return sum;
}

int main() {
    int n, cases = 0;
    while (~scanf("%d", &n)) {
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &pre[0][i]);
            pre[1][i] = sqrt(pre[0][i]);
            pre[0][i] += pre[0][i-1];
        }

        //处理前缀和
        for (int i = 1; i <= 64; i++) {
            bool flag = 0;
            for (int j = 1; j <= n; j++) {
                if (pre[i][j] != 1)
                    flag = 1;
                pre[i+1][j] = sqrt(pre[i][j]);
                pre[i][j] += pre[i][j-1];
            }
            //如果所有元素均为1,就不用处理后面的前缀和了
            if (!flag) {
                //times为最多多少次,所有数字均变为1
                times = i;
                break;
            }
        }

        build(1, 1, n);
        int m;
        scanf("%d", &m);
        printf("Case #%d:\n", ++cases);
        while (m--) {
            int top, x, y;
            scanf("%d %d %d", &top, &x, &y);
            if (x > y)
                swap(x, y);
            if (top) {
                printf("%lld\n", query(1, 1, n, x, y));
            }
            else {
                updata(1, 1, n, x, y);
            }
        }
        putchar('\n');
    }
}
汽车UDS诊断之诊断会话控制服务(0x10)深度剖析 DiagnosticSessionControl就是诊断会话控制。 请求消息定义 A_Data类型 参数名称 Cvt 字节值 助记符 #1 诊断会话控制请求SID M 0x10 DSC #2 子功能=[诊断会话类型] M 0x00-0xFF LEV_DS_ ... 阅读详情

相关推荐

初识数据结构之入门必懂——线性表(顺序表)

本文将介绍数据结构中的线性表与线性表中最简单的结构——顺序表

m0_64705485的博客 904

HDU 6547 Tree 树链剖分+线段树区间开根区间求和

http://acm.hdu.edu.cn/showproblem.php?pid=6547 wls 有三棵树,树上每个节点都有一个值 ai ,现在有 2 种操作: 1. 将一条链上的所有节点的值开根号向下取整; 2. 求一条链上值的和; 链的定义是两点之间的最短路。 Input 第一行两个数 n, q 分别代表树上点的数量和操作数量。 第二行 n 个整数,第 i 个数代表第 i 个点的值 ai。...

xiji333的博客 411

深入CRSF协议数据包:手撕STM32代码,教你像调试串口一样分析ELRS遥控数据流

本文深入解析CRSF协议数据包,通过手撕STM32代码,教你如何像调试串口一样分析ELRS遥控数据流。从硬件准备到数据包捕获状态机设计,再到高级数据分析技巧和实战应用,全面覆盖CRSF协议的解析与优化,帮助开发者构建稳定可靠的通信系统。

weixin_29194693的博客 337

HDU 4027 Can you answer these queries?

题目链接:Problem - 4027 (hdu.edu.cn) A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every atta

m0_55682843的博客 299

FPGA实战:从零构建eMMC控制器(Verilog篇)

本文详细介绍了如何使用Verilog从零构建FPGA上的eMMC控制器,涵盖eMMC接口基础、命令系统解析、关键模块设计及性能优化技巧。通过实战案例,帮助开发者掌握高速数据存储解决方案,提升嵌入式系统开发能力。

weixin_26802933的博客 297

ESP8266+ITR8307实战:如何用反射式光电管实现5cm远距离检测(附避坑指南)

本文详细介绍了如何利用ESP8266的ADC功能与ITR8307反射式光电管,通过调制解调、硬件电路优化及软件同步采样策略,实现5cm稳定远距离检测。文章提供了完整的硬件设计、代码实现与调优避坑指南,有效解决了环境光干扰与信号衰减难题,适用于智能车、自动化等需要可靠非接触检测的项目。

rgv234567的博客 263

HDU - 4027 Can you answer these queries? (线段树)

HDU - 4027 Can you answer these queries? 题 意:给你n个数字,q个操作。每次操作输入x,l,r。x= 0 ,代表把al到ar的值全部都开根号。x=1,代表求al到ar的和。 数据范围: 1&amp;amp;lt;=M,N&amp;amp;lt;=1e5 输入样例: 10 1 2 3 4 5 6 7 8 9 10 5 0 1 10 1 1 10 1 1 5 0 5 8 1 4...

子灬丶逾 242

74HC138译码器的原理和使用

A0,A1,A2为3位二进制加权地址输入端口,A2A1A0顺序组成的3位2进制数对应的十进制数x控制使能端口Yx';例如当A2A1A0 = 101 时,其他门输出端全为高电平,只有Y5'为低电平。 Y0-Y7为8个输出端口,其输出电平由A0,A2,A3,E1,E2,E3决定。

diksan的博客 6万+

Can you answer these queries?( HDU - 4027,线段树 + 细节)

一.题目链接: HDU-4027 二.题目大意: n 个数. 有两种操作. 0 X Y:将区间 [X, Y] 的数开方(向下取整) 1 X Y:查询区间 [X, Y] 的和. 三.分析: 直接线段树单点更新会 TLE,由于根号 7 次后向下取整为 1. 所以只需要记录每段区间被更新过的次数. 注意:所给的 X,Y 大小关系不确定因为这里 WA 了三天啊啊啊啊啊啊 555....

The___Flash的博客 288

8年ES运维经验整理出的Elasticsearch运维手册(超实用)

k1 : 控制非线性词频率归一化(饱和),Elasticsearch中默认值为1.2。用人能看懂的话说就是词语在文档中出现的次数对于得分的重要性。例如说我觉得在某些场景,一个搜索词在文档中出现越多则越接近我希望搜索的内容,就可以将这个参数调大一点。b :控制文档长度对于分数的惩罚力度。变量b处于分母上,它乘以刚刚讨论过的字段长度的比值,Elasticsearch中的b 默认值为0.75。如果b较大,则文档长度相对于平均长度的影响更大。

yonggeit的博客 5273

【STK】手把手教你利用STK进行仿真-STK软件简介02 STK专业分析模块

STK/Astrogator是一个交互式轨道机动和深空探测计划工具,用于飞行器运行及任务分析,通过定义推力模型、目标星历、飞行器姿态,提供轨道机动的解决及优化方案。应用Astrogator分析轨道机动的可见性和地面站覆盖,用户可以快速、方便地进行全局分析。任务控制序列保存在STK场景中,用于任务运行、快速制定精确轨道机动方案。为在轨运行的飞行器制定或执行机动计划时,分析人员可以根据飞行过程数据,如发动机定标参数、实际初始轨道,计算出推进器点火和点火时机数据,用于发出指令及精炼机动计划。

weixin_44184852的博客 1864

hdu 4027 Can you answer these queries? 线段树

 hdu 4027 Can you answer these queries?A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the b...

GYH0730的博客 620

自适应控制 (Adaptive Control) 算法详解及案例分析

自适应控制是一种能够在线调整控制器参数以适应系统动态变化的控制方法。其核心思想是通过实时估计系统参数或调整控制器参数,使系统在不确定性或动态变化的环境中仍能保持稳定性和性能。

闲人编程的博客 4083

HDU-4027-Can you answer these queries?(暴力线段树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目大意:n个数,两种操作,0.将[l,r]内的所有数开平方(四舍五入取ll),1.求[l,r]内的sum 思路:线段树板子,首先需要更新到最下面,1开平方还是1,所以一个数最多更新64次,然后记录一下是否需要开平发即可。 ACCode: #include<stdlib.h&gt...

永远鲜红の幼月的博客 324

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

深度学习工具包 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")

Can you answer these queries? HDU 4027 线段树

Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来值开根号下的值。有两种操作,第一种就是上面描述的那种,第二种就是询问某个区间内的船的战斗值的总和。 解题思路 使用线段树就不用多说了,关键是如果不优化的话会超时,因为每次修改都是需要递归...

weixin_30715523的博客 175

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

HDU-4027Can you answer these queries?(线段树)

Problem Description A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every attack of our secr

weixin_44313771的博客 2042

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

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

hdu4027Can you answer these queries?(线段树)

Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 13697    Accepted Submission(s): 3150 Problem Descriptio

ACMan 400

Can you answer these queries? HDU - 4027 线段树

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 思路:区间查询套用模板,关键是区间更新的时候,区间更新的时候要对每一个点取平方根的操作,要注意的是每一个点最多取7次根号就可以到1,所以当区间的和等于区间长度,就不需要再进行更新。 每一个down的操作就等于单点更新+区间判断. 坑点就是,给的x,y  并不一定满足x #i

Peppermint__的博客 310

线段树 HDU—4027 Can you answer these queries?

链接: link. 题意: 输入一个n表示n个数,然后输入n个数,输入m表示m个操作,有2种操作: 1、0 x y 表示x到y这个区间到数都开根号 2、1 x y 求出x到y区间和 思路: 毫无疑问利用线段树求区间和,但是每次都把一个区间的每个数都开根号就会超时,我们知道一个数一直开根号,到最后一定变为1,所以我们同时记录一下一个区间内的最大值,如果这个区间的最大值是1,那么就不用给这个区间的数开根号,就不用继续往下找,降低时间复杂度。 代码: #include <iostream> #incl

HHeyanjie的博客 145

HDU4027 Can you answer these queries?(线段树)

题意: 给我们一个数组,有两种操作,第一个是修改区间的值,使其区间的值全部变为原来的平方根

the best 的博客 601

hdu 4027 Can you answer these queries?(线段树)

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4027 题意:给一个数组序列, 数组长度为100000,现在有两种操作, 一种操作是将某一个固定区间所有数开方(向下取整),另一种操作是询问某个区间的所有数字之和。 看似区间开平方很复杂其实挺简单的,因为10^18开方到1也不用几次所以只要考虑遍历到的区间是否满足区间总和为r-l+1,满足...

awow80285的博客 97

HDU4027 Can you answer these queries?【线段树】

Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 23332    Accepted Submission(s): 5550   Problem Description A ...

海岛Blog 969

【HDU 4027 Can you answer these queries?】+ 线段树

Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 14091 Accepted Submission(s): 3274Problem Description A lot

楚江枫 535

【线段树】【HDU4027】Can you answer these queries?

博客主页: https://blog.youkuaiyun.com/qq_50285142 欢迎点赞????收藏✨关注❤留言 ???? 如有错误,敬请指正 ????虽然生活很难,但我们也要一直走下去???? 题目链接 一个序列,可以进行两次操作:1.对区间内的每个元素取平方根,取整数 2.询问区间的和 思路: 线段树乍一看是处理区间的问题,但是处理区间的问题求总和比较麻烦。 但是从取平方根入手,发现最大的2642^{64}264取7次就会变成一,如果变成一的话,我们对变成一的区间进行特判(区间长度=区间和),

行码棋 420

HDU4027 Can you answer these queries? —— 线段树 区间修改

题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Ea...

alince20008的博客 153
上一篇: HDU1394 - Minimum Inversion Number(线段树)
下一篇: CodeChef MOU2H - Mountain Holidays 2 (DP)
ACM_Fish
博客等级 码龄10年 69粉丝 76原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值