Smiling & Weeping

                 ---- 姑娘,倘若,我双手合十的愿望里有你呢

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

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.
思路:这道题目是一道中规中矩的线段树,但是有点小坑,需要牢记,以后长一下记性:
if(L > R) swap(L , R);   (•́へ•́╬)不要问我怎么知道的(•́へ•́╬)
对了,对于无结束符可以使用 sacnf("%d",&n) != EOF 来判断
那么现在上代码:
 1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cmath>
5 using namespace std;
6 typedef long long ll;
7 const int maxn = 100100;
8 ll a[maxn] , tree[maxn<<2];
9 int t , n;
10 #define ls(p) p<<1
11 #define rs(p) p<<1|1
12 void push_up(int p)
13 {
14 tree[p] = tree[ls(p)] + tree[rs(p)];
15 }
16 void build(int p , int pl , int pr)
17 {
18 if(pl == pr) {tree[p] = a[pl]; return ; }
19 int mid = pl+pr >> 1;
20 build(ls(p) , pl , mid);
21 build(rs(p) , mid+1 , pr);
22 push_up(p);
23 }
24 void update(int L ,int R , int p , int pl , int pr)
25 {
26 if(pl == pr) {tree[p] = sqrt(tree[p]); return ;}
27 if(tree[p] <= pr-pl+1) return ;
28 int mid = pl+pr >> 1;
29 if(L <= mid) update(L , R , ls(p) , pl , mid);
30 if(R > mid) update(L , R , rs(p) , mid+1 , pr);
31 push_up(p);
32 }
33 ll query(int L , int R , int p , int pl, int pr)
34 {
35 if(L <= pl && pr <= R)
36 return tree[p];
37 int mid = pr+pl >> 1;
38 ll res = 0;
39 if(L <= mid) res += query(L , R , ls(p) , pl , mid);
40 if(R > mid) res += query(L , R , rs(p) , mid+1 , pr);
41 return res;
42 }
43 int main()
44 {
45 int ind = 0;
46 while(scanf("%d",&n) != EOF)
47 {
48 int k;
49 printf("Case #%d:\n",++ind);
50 for(int i = 1; i <= n; i++)
51 scanf("%lld",&a[i]);
52 scanf("%d",&k);
53 build(1,1,n);
54 for(int i = 1; i <= k; i++)
55 {
56 int opt , L , R;
57 scanf("%d%d%d",&opt,&L,&R);
58 if(L > R) swap(L , R);
59 if(opt == 0)
60 {
61 update(L , R , 1 , 1 , n);
62 }
63 else
64 {
65 printf("%lld\n",query(L , R , 1 , 1 , n));
66 }
67 }
68 printf("\n");
69 }
70 }

青山不改,绿水长流,我们下次再见ヾ( ̄▽ ̄)Bye~Bye~

线段树hdu-4027的更多相关文章

  1. bzoj 3038: 上帝造题的七分钟2 线段树||hdu 4027

    3038: 上帝造题的七分钟2 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1066  Solved: 476[Submit][Status][Dis ...

  2. 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )

    在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...

  3. 最大矩阵覆盖权值--(静态连续最大子段 (线段树) )-HDU(6638)Snowy Smile

    这题是杭电多校2019第六场的题目 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6638 题意:给你平面上n个点,每个点都有权值(有负权),让你计算一 ...

  4. 敌兵布阵(线段树HDU 1166)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...

  5. HDU 6464 权值线段树 && HDU 6468 思维题

    免费送气球 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. 区间第k大问题 权值线段树 hdu 5249

    先说下权值线段树的概念吧 权值平均树 就是指区间维护值为这个区间内点出现次数和的线段树 用这个加权线段树 解决第k大问题就很方便了 int query(int l,int r,int rt,int k ...

  7. 线段树 HDU 3397(真)

    5 种操作  0 1 然后 异或 似乎这种2个更新的先后每次都搞不清 覆盖有覆盖就可以不异或 也不知道为什么 #include<stdio.h> #include<string.h& ...

  8. 线段树 HDU 3397

    5种操作 具体看代码 #include<iostream> #include<stdio.h> #include<string.h> #include<alg ...

  9. 线段树 HDU 3308

    t 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y   2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 #include< ...

  10. 二维线段树 HDU 1823最简单的入门题

    xiaoz 征婚,首先输入M,表示有M个操作. 借下来M行,对每一行   Ih a l     I 表示有一个MM报名,H是高度, a是活泼度,L是缘分. 或   Q h1 h2 a1 a2    求 ...

随机推荐

  1. 【python基础】基本数据类型-数字类型

    Python3 支持int(整型数据).float(浮点型数据).bool(布尔类型) 1.int(整型数据) 在Python 3里,只有一种整数类型 int,表示为长整型.像大多数语言一样,数值类型 ...

  2. NLM 公布了一个新的重新设计的 PubMed 数据库

    经常使用 PubMed 的童鞋可能已经发现,美国国家医学图书馆(NLM)在今年 10 月份左右发布了一个新的重新设计的版本以取代 PubMed 数据库的现有版本,新版本现在已经上线,可以通过下面的链接 ...

  3. cmd+ssh配置远程服务器Anaconda3_2023+pytorch

    一.上传Anaconda3到远程服务器 注意:如果要将这个东西安装在anaconda3文件夹里的话,当前这个目录里不能有这个文件夹.(安的时候会自动创建) 二.安装Anaconda3 1. win+r ...

  4. jQuery控制图片墙自动+手动淡入淡出切换

    先来看一下效果:http://39.105.101.122/myhtml/Jquery/img_switch/img_switch.html(甄嬛的眼睛有木有变大) 添加一个div(class=con ...

  5. sql server注入rce实践

    背景:在漏洞挖掘中,合理的利用sql注入,可以把注入转换成rce,使一个高危漏洞变成严重漏洞.在红蓝对抗中,利用注入rce,实现内网横向移动.笔者基于漏洞挖掘和红蓝对抗上遇到的sql server注入 ...

  6. 打包 IPA processing failed 失败

    查看报错日志:有些SDK含有x86_64架构,移除即可 1. cd 该库SDK路径下 2.执行 lipo -remove x86_64 BaiduTraceSDK -o BaiduTraceSDK 解 ...

  7. 一体化元数据管理平台——OpenMetadata入门宝典

    大家好,我是独孤风,一位曾经的港口煤炭工人,目前在某国企任大数据负责人,公众号大数据流动主理人.在最近的两年的时间里,因为公司的需求,还有大数据的发展趋势所在,我开始学习数据治理的相关知识.今天给大家 ...

  8. ASP.NET MVC4 学习笔记-4

    添加验证--Adding Validation 现在我们要为程序增加数据验证.如果不增加数据验证的话,我们的用户可能会输入错误的数据或者提交一个空白的表格. 在MVC应用程序中,数据验证通常要在域模型 ...

  9. Maven项目配置

    pom.xml配置 配置编码格式为UTF-8 <properties> <project.build.sourceEncoding>UTF-8</project.buil ...

  10. win10使用Docker Desktop启动mysql报错:Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3306 -> 0.0.0.0:0: listen tcp 0.0.0.0:3306:

    问题描述 今天上班用wind10电脑启动Docker Desktop使用MySQL,突然间报了一个错,错误如下: Error response from daemon: Ports are not a ...