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. 小程序使用wx.navigateTo无法跳转到加了tabBar的页面

    随着小程序的不断更新,发现目前的小程序版本使用navigator无法跳转到加了tabBar的页面:后来使用redirectTo进行跳转也不行:在刚开始也是纠结了好久一直找不到解决办法.最后从官方文档中 ...

  2. R 语言常用操作与函数汇总

    总结了一下 R 语言中常用的一些操作与函数使用,抛砖引玉,分享一下给大家,如有错误的地方欢迎留言指正. 怎样显示 R 软件中某个包中包含的全部数据集? > library(MASS)> d ...

  3. Terraform 改善基础架构的十个最佳实践

    Terraform 是一种非常流行的开源 IaC(基础设施即代码)工具,用于定义和提供完整的基础设施.Terraform 于 2014 年推出,其采用率已在全球范围内快速增长,越来越多的开发人员正在学 ...

  4. 三分钟快速了解什么是MES系统

    大家好,我是Edison. 近日我打算系统学习和整理一下MES/MOM系统相关的领域知识,从而构建我的业务域知识背景.万丈高楼平地起,我们先从快速了解什么是MES系统开始吧! 作为IT技术从业者,特别 ...

  5. JS工具函数

    工具函数 用于工程化开发,记录,备用 返回 [min, max) 间的随机整数 /** 返回 [min, max) 间的随机整数 */ export function getRandom(min, m ...

  6. 【AGC】Connect API报错submit failed的相关问题

    ​[关键字] AGC.Connect API.Publishing API [问题描述] 开发者反馈在使用AGC的Connect API提交发布时,报出了[cds]submit failed, add ...

  7. 本地python调试 问题笔记

    ImportError: cannot import name 'int_classes' from 'torch._six' 把  "from torch._six import stri ...

  8. Java使用joml计算机图形学库,将3D坐标旋转正交投影转为2D坐标

    最近遇到了一个困扰我许久的难题,现将解决方案分享出来 由于我们的项目侧重点在前端绘图,导致了前后端工作量不协调,我后端接口很快就能写完,而前端一个图要画好久,领导见状将前端的任务分到后端一部分用Jav ...

  9. 2023-07-09:给定N、M两个参数, 一共有N个格子,每个格子可以涂上一种颜色,颜色在M种里选, 当涂满N个格子,并且M种颜色都使用了,叫一种有效方法。 求一共有多少种有效方法。 1 <= N,

    2023-07-09:给定N.M两个参数, 一共有N个格子,每个格子可以涂上一种颜色,颜色在M种里选, 当涂满N个格子,并且M种颜色都使用了,叫一种有效方法. 求一共有多少种有效方法. 1 <= ...

  10. .NET Core 3.1使用docker打包并部署

    目录 简介 环境介绍 开发环境 部署环境 编写Dockerfile文件 生成Docker镜像 运行容器 访问接口 结语 简介 本文主要说明使用.NET Core 3.1搭建的站点如何使用docker打 ...