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): 16260 Accepted Submission(s): 3809
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.
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 263.
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.
- #include <stdio.h>
- #include <iostream>
- #include <algorithm>
- #include <cstdlib>
- #include <sstream>
- #include <numeric>
- #include <cstring>
- #include <bitset>
- #include <string>
- #include <deque>
- #include <stack>
- #include <cmath>
- #include <queue>
- #include <set>
- #include <map>
- using namespace std;
- #define INF 0x3f3f3f3f
- #define LC(x) (x<<1)
- #define RC(x) ((x<<1)+1)
- #define MID(x,y) ((x+y)>>1)
- #define CLR(arr,val) memset(arr,val,sizeof(arr))
- #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
- typedef pair<int, int> pii;
- typedef long long LL;
- const double PI = acos(-1.0);
- const int N = 100010;
- struct seg
- {
- int l, mid, r;
- LL sum;
- int cnt;
- };
- seg T[N << 2];
- LL arr[N];
- void pushup(int k)
- {
- T[k].sum = T[LC(k)].sum + T[RC(k)].sum;
- }
- void build(int k, int l, int r)
- {
- T[k].l = l;
- T[k].r = r;
- T[k].mid = MID(l, r);
- T[k].sum = T[k].cnt = 0;
- if (l == r)
- T[k].sum = arr[l];
- else
- {
- build(LC(k), l, T[k].mid);
- build(RC(k), T[k].mid + 1, r);
- pushup(k);
- }
- }
- void SQ(int k, int l, int r)
- {
- if (l <= T[k].l && T[k].r <= r)
- ++T[k].cnt;
- if (T[k].cnt >= 7)
- return;
- if (T[k].l == T[k].r)
- {
- T[k].sum = sqrt(T[k].sum);
- return ;
- }
- if (r <= T[k].mid)
- SQ(LC(k), l, r);
- else if (l > T[k].mid)
- SQ(RC(k), l, r);
- else
- SQ(LC(k), l, T[k].mid), SQ(RC(k), T[k].mid + 1, r);
- pushup(k);
- }
- LL query(int k, int l, int r)
- {
- if (l <= T[k].l && T[k].r <= r)
- return T[k].sum;
- else
- {
- if (r <= T[k].mid)
- return query(LC(k), l, r);
- else if (l > T[k].mid)
- return query(RC(k), l, r);
- else
- return query(LC(k), l, T[k].mid) + query(RC(k), T[k].mid + 1, r);
- }
- }
- int main(void)
- {
- int i;
- int tcase = 1;
- int n, m;
- while (~scanf("%d", &n))
- {
- for (i = 1; i <= n; ++i)
- scanf("%I64d", &arr[i]);
- build(1, 1, n);
- scanf("%d", &m);
- printf("Case #%d:\n", tcase++);
- while (m--)
- {
- int l, r, ops;
- scanf("%d%d%d", &ops, &l, &r);
- if (l > r)
- swap(l, r);
- if (!ops)
- SQ(1, l, r);
- else
- printf("%I64d\n", query(1, l, r));
- }
- puts("");
- }
- return 0;
- }
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 u ...
- hdu 4027 Can you answer these queries? 线段树区间开根号,区间求和
Can you answer these queries? Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...
- HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
题目 线段树 简单题意: 区间(单点?)更新,区间求和 更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...
- hdu 4027 Can you answer these queries? 线段树
线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...
- HDU 4027 Can you answer these queries? (线段树成段更新 && 开根操作 && 规律)
题意 : 给你N个数以及M个操作,操作分两类,第一种输入 "0 l r" 表示将区间[l,r]里的每个数都开根号.第二种输入"1 l r",表示查询区间[l,r ...
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- HDU-4027-Can you answer these queries?线段树+区间根号+剪枝
传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...
- hdu 4027 Can you answer these queries?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
随机推荐
- python_63_装饰器6
#decorator意思:1.装饰器 2.语法糖 import time user,passwd='qi','123' def auth(func): def wrappper(*args, **kw ...
- CUDA编程时,线程块的处理方法
- 标准对象 -------JavaScript
本文摘要:http://www.liaoxuefeng.com/ 在JavaScript的世界里,一切都是对象. 但是某些对象还是和其他对象不太一样.为了区分对象的类型,我们用typeof操作符获取对 ...
- 项目:Vue+node+后台管理项目小结
序:本文主要分两块说:项目机制,具体用到的知识块. 1. 项目机制 项目的原型以vue-cli为原型,进行项目的初步构建.项目以node.js服务和webpack打包机制为依托,将.vue文件打包为浏 ...
- Websocket教程SpringBoot+Maven整合
1.大话websocket及课程介绍 简介: websocket介绍.使用场景分享.学习课程需要什么基础 2.课程技术选型和浏览器兼容讲解 简介: 简单介绍什么是springboot.socketjs ...
- idea 创建springboot工程
公司最近用springboot做微服务开发 1,使用idea创建一个spring initializr 工程 2,点击next 3,配置好后继续next 4,可以勾选上web,继续next 5,fin ...
- webpack4.x ,1基本项目构建 详解
1.先创建个文件夹 比如叫 webApp 用编译器打开 2.安装全局的webpack 和webpack-cli 及 webpack-dev-server 命令如下 npm install webpac ...
- C++大数问题
1.大数的加法 语法:add(char a[],char b[],char s[]); 参数: a[]:被加数,用字符串表示,位数不限 b[]:加数,用字符串表示,位数不限 s[]:结果,用字符串表示 ...
- 51nod——2476 小b和序列(预处理 思维)
对于每一个元素,预处理出它作为最小值,两边可以作用到的最大位置.比如下标∈[0,8]的这个数组:1 8 6 2 5 4 3 8 7,1可以作用到所有区间,2可以作用到区间[1,8],第一个8可以作用到 ...
- 牛客小白月赛5 A 无关(relationship) 【容斥原理】【数据范围处理】
题目链接:https://www.nowcoder.com/acm/contest/135/A 题目描述 若一个集合A内所有的元素都不是正整数N的因数,则称N与集合A无关. 给出一个含有k个元素的 ...