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. ThreadLocal 的应用及原理

    1. 是什么 JDK 对 ThreadLocal 类的描述为: 此类提供线程局部变量.这些变量与普通变量的不同之处在于,每个访问一个变量的线程(通过其get或set方法)都有自己的.独立初始化的变量副 ...

  2. OCR -- 文本检测

    目录 目标检测: 文本检测: 检测难点: 检测方法: 基于回归的文本检测 水平文本检测 任意角度文本检测 弯曲文本检测 基于分割的文本检测 代码示例 可视化文本检测预测 DB文本检测模型构建 back ...

  3. 百度飞桨(PaddlePaddle) - PP-OCRv3 文字检测识别系统 基于 Paddle Serving快速使用(服务化部署 - CentOS 7)

    目录 Paddle Serving服务化部署实战 准备预测数据和部署环境 环境准备 安装 PaddlePaddle 2.0 安装 PaddleOCR 准备PaddleServing的运行环境, 模型转 ...

  4. Java流程控制和循环(基础语法学习)

    一.流程控制 1.定义 ​ 在一个Java程序中,各条语句的执行对程序的结果有直接影响,也就是说 各个语句的执行顺序对程序的结果有直接影响. ​ 在程序中 ,可能出现不同的执行顺序,必须 自上而下顺序 ...

  5. 我们浏览 GitHub 时,经常看到 "WIP" 的分支,即 Work In Progress,正在开发过程中(尚不能独立的运行)的代码。这部分的代码在 Github/Gitlab 中将禁用“合......

    本文分享自微信公众号 - 生信科技爱好者(bioitee).如有侵权,请联系 support@oschina.cn 删除.本文参与"OSC源创计划",欢迎正在阅读的你也加入,一起分 ...

  6. 【论文阅读】Uformer:A General U-Shaped Transformer for Image Restoration

    前言 博客主页:睡晚不猿序程 首发时间:2023.6.8 最近更新时间:2023.6.8 本文由 睡晚不猿序程 原创 作者是蒻蒟本蒟,如果文章里有任何错误或者表述不清,请 tt 我,万分感谢!orz ...

  7. 【IntelliJ】添加javaweb、tomcat语法支持

    默认情况下:idea不支持javaweb的语法 但,我们的期望是: 解决方法:配置tomcat如下: (假设你已经配置好了tomcat)接下来: 1.打开[项目结构(快捷键:Ctrl + Shift ...

  8. WPF 入门笔记 - 05 - 依赖属性

    如果预计中的不幸没有发生的话,我们就会收获意外的喜悦. --人生的智慧 - 叔本华 WPF属性系统 这一部分是中途加的,直接依赖属性有点迷糊,正好有了绑定的基础,理解起来还一些. WPF提供一组服务, ...

  9. ChatGPT使用案例,助你快速上手,做事事半功倍

    ChatGPT介绍 首先我们来看一下chat-gpt自己的介绍: ChatGPT的发展历程 2015年,OpenAI成立,致力于研究和开发人工智能技术.在成立初期,OpenAI的创始人之一Elon M ...

  10. Java扩展Nginx之一:你好,nginx-clojure

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 关于Nginx扩展 以欣宸自己为例,对一个java程序 ...