HDU 4027 Can you answer these queries? (线段树 区间更新)

RKNN3588——YOLOv8的PT模型转RKNN模型 1. 首先克隆rknn修改后的ultralytics版本项目到本地主要是修改了源码的ultralytics/nn/modules/head.py和ultralytics/engine/exporter.py两个文件。2. 使用修改后的ultralytics对pt模型进行模型转换,此处的format=rknn代表支持rknn后续的转换,而不是用onnx,一定要注意!!! 阅读详情

题目地址:点击打开链接


题意:给定100000个数,两种操作,0 i j表示将i j这段的数字都开根号(向下取整),1 i j表示查询i j之间的所有值的和(所有的和都不超过64位)


思路:

我们可以很容易的发现,一个数k(k<=2^63-1)在经过最多6,7次的开平方根后,必然会变成1,而且当1的平方根

也是1,也就是说当一个数为1的时候,我们没有必要对它进行操作和更新;而且一个很大的数仅仅经过6,7次就可以

变成1;


所以到这里我们因该就可以形成一个解题的大体思路了:


每当我们要进行更新操作的时候,我们先判断一下这个区间是否有必要进行更新(若全都是1就没有更新的必要了);


用一个lazy数组记录该区间是否都为1,只有当不都为1的时候才更新,否则不需要更新。


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
ll tree[maxn*4], lazy[maxn*4];//lazy数组记录他的孩子们是否都已经变成了1
int n, m;

void built(int root, int l, int r)
{
    lazy[root] = 0;
    if(l == r)
    {
        scanf("%lld", &tree[root]);
        return;
    }
    int mid = (l+r)/2;
    built(root*2, l, mid);
    built(root*2+1, mid+1, r);
    tree[root] = tree[root*2]+tree[root*2+1];
    lazy[root] = lazy[root*2]&&lazy[root*2+1];
}

ll query(int root, int l, int r, int i, int j)
{
    if(i <= l && j >= r) return tree[root];
    int mid = (l+r)/2;
    ll suml = 0, sumr = 0;
    if(mid >= i) suml = query(root*2, l, mid, i, j);
    if(mid < j) sumr = query(root*2+1, mid+1, r, i, j);
    return suml+sumr;
}

void update(int root, int l, int r, int i, int j)
{
    if(l == r)
    {
        tree[root] = floor(sqrt(tree[root]));
        if(tree[root] <= 1) lazy[root] = 1;
        return ;
    }
    int mid = (l+r)/2;
    if(mid >= i && !lazy[root]) update(root*2, l, mid, i, j);
    if(mid < j && !lazy[root]) update(root*2+1, mid+1, r, i, j);
    tree[root] = tree[root*2]+tree[root*2+1];
    lazy[root] = lazy[root*2]&&lazy[root*2+1];
}

int main(void)
{
    int ca = 1;
    while(cin >> n)
    {
        built(1, 1, n);
        scanf("%d", &m);
        printf("Case #%d:\n", ca++);
        while(m--)
        {
            int cmd, x, y;
            scanf("%d%d%d", &cmd, &x, &y);
            if(x > y) swap(x, y);
            if(cmd) printf("%lld\n", query(1, 1, n, x, y));
            else update(1, 1, n, x, y);
        }
        cout << endl;
    }
    return 0;
}


Can you answer these queries?

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 15003    Accepted Submission(s): 3516


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 secret weapon, it could decrease the endurance of a consecutive part of battleships by make their endurance to the square root of it original value of endurance. During the series of attack of our secret weapon, the commander wants to evaluate the effect of the weapon, so he asks you for help.
You are asked to answer the queries that the sum of the endurance of a consecutive part of the battleship line.

Notice that the square root operation should be rounded down to integer.
 

Input
The input contains several test cases, terminated by EOF.
  For each test case, the first line contains a single integer N, denoting there are N battleships of evil in a line. (1 <= N <= 100000)
  The second line contains N integers Ei, indicating the endurance value of each battleship from the beginning of the line to the end. You can assume that the sum of all endurance value is less than 2 63.
  The next line contains an integer M, denoting the number of actions and queries. (1 <= M <= 100000)
  For the following M lines, each line contains three integers T, X and Y. The T=0 denoting the action of the secret weapon, which will decrease the endurance value of the battleships between the X-th and Y-th battleship, inclusive. The T=1 denoting the query of the commander which ask for the sum of the endurance value of the battleship between X-th and Y-th, inclusive.
 

Output
For each test case, print the case number at the first line. Then print one line for each query. And remember follow a blank line after each test case.
 

Sample Input
  
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 8
 

Sample Output
  
Case #1: 19 7 6
 

Source
 


库存管理系统项目部署方案(基于jdk8) 不需要安装到服务器,运维本地安装就行,主要是用来编译前端代码的。构建完成后将dist文件夹复制到服务器内。 阅读详情

相关推荐

STM32F103C8T6+A4988驱动42步进电机全流程(附接线图+代码解析)

本文详细介绍了使用STM32F103C8T6单片机与A4988驱动模块控制42步进电机的完整流程。内容涵盖硬件接线图解析、电流设置、GPIO驱动代码编写以及细分控制等核心实践,旨在帮助嵌入式开发者和DIY爱好者快速实现精准运动控制,适用于3D打印机、CNC等需要精密定位的项目。

Python的专栏 795

Can you answer these queries 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. Each of the battleships can be marked a value of end...

李兆龙的博客 665

Dofbot机械臂从零部署笔记(1)——ROS之创建URDF模型、配置Moveit和MotionPlanning

Dofbot机械臂从零部署笔记(1)——ROS之创建URDF模型、配置Moveit和MotionPlanning

takedachia的博客 8698

HDU - 4027 Can you answer these queries? (线段树 区间更新 区间查询)

HDU - 4027  http://acm.hdu.edu.cn/showproblem.php?pid=4027 题意:更新的时候把要求区间内的值都更新为自己开根号,查询时查询区间和。 思路:  感觉自己有个不好的习惯,有题目没思路时老是容易去看题解或是discuss,这个习惯真的要改一下。 这个题由于是根号,所以必须得更新到点,然后会发现,每次开根号一个数会很快变成1,这时再对这段区间

shinimashzi 234

VIO实战前传:手把手教你解读Kalibr双目IMU标定报告与参数应用

本文详细解析Kalibr双目IMU联合标定报告的核心参数与应用方法,涵盖重投影误差分析、IMU误差指标解读、关键变换矩阵原理及VINS-Fusion实战配置。通过手把手教学帮助开发者准确理解标定结果,解决VIO算法落地中的参数配置难题,提升视觉惯性里程计的系统稳定性与精度。

weixin_42699679的博客 334

R语言孟德尔随机化环境搭建:手把手教你搞定gwasvcf、gwasglue等包的安装报错(附本地安装包)

本文详细介绍了R语言中孟德尔随机化环境搭建的全流程,重点解决gwasvcf、gwasglue等包的安装报错问题。从依赖关系解析到GitHub访问配置,再到离线安装方案,手把手教你搭建完整的分析环境,特别适合生物信息学新手快速上手。

weixin_29093017的博客 216

HDU 4027 Can you answer these queries?(线段树 区间不等更新)

https://vjudge.net/problem/HDU-4027#author=SUDA2019 题意 输入n个数 然后有两种操作 输入0时将给定区间所有数都变为自己的开方 输入1输出给定区间所有数的和 虽然是区间更新 但每个点更新的不一样 因此只能对单点进行更新 其实一个点最多被更新7次 \(2^{64}\) 开平方7次后就变为1了 如果某个区间的数都变为了1 ...

橘嘉禾 125

利用运放设计简单有源滤波器(低通、高通、带通)

本文旨在帮助刚接触模电的同学快速设计一个实用可靠的运放,故我将不会说一些晦涩难懂的原理,只给出仿真电路图。

WeiTong0527的博客 3万+

HDU 4027 Can you answer these queries?(线段树区间更新)

题目链接: 戳我 题目大意: 一组数字,1....n,数字范围是 1 到 2^63 有两种操作, 0x y 代表 从x到y,每个数都开平方 1 x y 代表 从x到y所有数的和 样例解释 略 解题思路: 一个数不停的开平方,肯定有 变成 1 的时候,当一个数是1时,在开平方就没有意义了,所以对于一个区间都是1的,要标记掉,这样更新的时候就节省时间了,如果这个区间不全是...

aocang4831的博客 162

世界职业院校技能大赛商贸赛道项目参考逐字稿一

商贸赛道“智选优品”—基于大数据与AI驱动的跨境电商平台项目参考逐字稿您订阅本专栏后即可`永久享有所有文章的查阅权`,希望我们更新的参考资料能帮助到您。如果您需要我们团队赋能培训可联系我(企业一线工程师及国一获奖选手在线培训支持:每周直播精讲(可回放,支持弹幕答疑)、代码Review+技术售后(拉群随时问,12h内响应)、④路演PPT+答辩话术一对一点评,评委视角提前彩排、适合:中职/高职赛项选手、指导老师带队、校企工作室、整校打包另谈(可开发票))

我是网络安全兼技能大赛工程师,专注网络安全技术学习与技能大赛实战!持续分享最新的技术文章,帮你少走弯路,一起在技术赛道上进步~ 1591

【KingSCADA】如何建立硬件系统及相关变量

本篇主要讲解如何定义设备,如何定义变量。KingSCADA3.8的采集系统是指负责和现场设备进行通讯,并采集现场数据和控制现场数据的模块,称之为采集器,也叫IOServer应用,它是一组独立的应用程序,可以脱离KingSCADA3.8软件,它依赖于KingSCADA3.8驱动产品,通过驱动与IO设备进行通讯。采集系统由通讯链路,设备,数据块组成。链路:链路是指计算机通过什么方式(接口)与设备进行连接,链路类别:串口,以太网,GPRS,Modem,通信卡,采集卡,无链路。

做有价值的事,积累有价值的笔记! 1万+

HDU - 4027 Can you answer these queries? (线段树 区间更新区间查询)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027点击打开链接 Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(

xuejye的博客 212

CDD那些事 - DID and SecurityAccess

本文介绍了SecurityAccessSID27的安全访问配置流程:1.通过StateGroups添加Level2群组;2.在Classes定义L2子功能;3.配置4步解锁流程,选择对应解锁等级;4.在DiagnosticInstance设置请求响应。同时说明了DID配置的两种方式:在DIDs页面定义或通过Identification页面创建,前者定义更全面。文章还提到ServiceList支持view/edit模式,其中edit模式可配置DID的多服务支持(如同时支持SID22读取和SID2E写入),但该

ziteng21的博客 256

Can you answer these queries? HDU - 4027【线段树+区间不等更新】

区间每个点的值都开方。   由于数据范围,开方的次数较小。一个点开方的次数不超过7次,所以次数可以做到每个点都修改,同时注意限制修改次数。 #include <bits/stdc++.h>//线段树区间不等更新 using namespace std; const int N=1e5+5; typedef long long ll; ll a[N],tree[N<<2]; ...

weixin_43184669的博客 181

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

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 battleships can be marked a value o...

weixin_44757834的博客 164

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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): 15021    Accepted Submission(s): 3526 Problem Descriptio

K键盘里的青春K 694

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

HDU - 4027 -- Can you answer these queries?【线段树区间更新 + 剪枝】

题意 有n个敌方战舰,每一艘战列舰都标明其耐力值。对于我们的秘密武器的每一次攻击,它都可以通过使战舰的耐久力减到原耐久力值的平方根来降低其连续的耐久力。现在给出m个查询,每个查询包含T, X, Y T = 1;查询x到y战舰的耐力总值 T = 0;x到y的每搜战舰的耐力值减到原来的一半 思路 ps:本以为是一个简单的区间修改 + 区间查询,结果T了。 看了题解才发现可以剪枝。当每个战舰的耐力值减少到1时,就不会再减少了,因为1的平方根就为1. 所以在区间修改的时候加一个判断条件即可。 还有一个坑点

qq_45249273的博客 204

HDU 4027 Can you answer these queries? (线段树变着花样让你区间更新)

题意:给一个数组序列, 数组长度为100000,现在有两种操作, 一种操作是将某一个固定区间所有数开方(向下取整),另一种操作是询问某个区间的所有数字之和。 坑点:区间的左右不是按顺序给的(RE的原因) 思路: 单点更新到子叶节点肯定药丸 1e5*1e5(TLE的原因)。 所以考虑使用区间更新。 这个题的更新操作是对子叶节点开方,而子叶节点的最小值是1。 就是说区间的最小值就是righ

DT2131 420

hdu4027Can 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

MissZhou要努力 736

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 battleships can be marked a value of end...

深海沧澜的博客 257

hdu_4027Can 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): 8808    Accepted Submission(s): 2009 Problem Description

西北有高楼的专栏 434

HDU 4027 Can you answer these queries?【线段树+区间更新】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 分析:一个区间包含n个数,q次询问(两个操作):            0 x y 把区间(x,y)内的没个数开方            1 x y 查询区间(x,y)的和 我们可以开个标记记录一下当前要更新的区间是否全为1(1开方还是1,属于无用操作,不用更新),不全为1,我们

Jane_JXR的博客 474

HDU 4027 Can you answer these queries?——其实是点更新的区间更新线段树

题意:给定一个序列,每次操作可以把一个区间内的所有数变成原来数字的开方,求序列和 思路:表面上是区间更新,但是每个数开方这种操作区间更新的慵懒标记难以做到,所以这个题不用慵懒标记,而是直接采用 单节点更新的思想,但是单节点更新一定会超时,所以做一个剪枝:当当前区间的值全为1时直接return,不进行任何更新,这是显然的,1开方还是1,更新的话只会徒增复杂度,其他的按照一般的模板写就可以了 #i

hao_zong_yin的博客 468

hdu 4027 Can you answer these queries?(线段树——区间更新)(思路)

Can 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. Eac

Darkarts 898

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): 17754    Accepted Submission(s): 4163 Problem D

riba2534的博客 590

hdu4027——Can 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 m

Beyond the Sora 1059
上一篇: ZOJ 1610 Count the Colors(线段树 区间覆盖)
下一篇: POJ 2182 Lost Cows (树状数组+二分 / 线段树 / 枚举)
cillyb
博客等级 码龄11年 225粉丝 497原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值