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. STM32H5移植zbar记录

    ZBar是一种流行的二维码扫描和解码工具,它在嵌入式系统中拥有广泛的应用.在嵌入式系统中,我们面临着有限的资源和更严格的性能要求,因此,选择适当的库来完成特定的任务非常重要. ZBar适用于各种嵌入式 ...

  2. 图解MySQL在Linux下的安装与配置

    MySQL简介 MySQL是最流行的RDBMS(Relational Database Management System:关系数据库管理系统)之一,被广泛地应用在互联网上的中小型网站中.关联数据库将 ...

  3. 基于SqlSugar的开发框架循序渐进介绍(30)-- 整合客户关系管理系统模块功能

    以前在随笔<Winform开发框架之客户关系管理系统(CRM)的开发总结系列1-界面功能展示 >的几篇随笔中介绍过基于WInform开发框架开发的CRM系统,系统的功能主要也是围绕着客户相 ...

  4. Springboot+actuator+prometheus+Grafana集成

    本次示例以Windows示例 推荐到官网去下载:Windows版的应用程序 下载最新版 prometheus-2.37.8.windows-amd64 压缩包:解压就行 下载最新版 grafana-9 ...

  5. Linux设置多个Tomcat开机自启动

    Linux设置多个Tomcat开机自启动 前言 一台服务器上有多个tomcat环境,重启服务器后,每次需要手动一个个启动服务,非常麻烦,于是可以设置tomcat开机自启动. tomcat开机自启动非常 ...

  6. flutter 的 in_app_web_view实现下载功能

    flutter与前端交互,利用in_app_web_view实现下载功能: 首先下载库,终端输入 flutter pub add flutter_inappwebview 之后导出 import 'p ...

  7. .Net7矢量化的性能优化

    前言 矢量化是性能优化的重要技术,也是寄托硬件层面的优化技术.本篇来看下. 概括 一:矢量化支持的问题: 矢量化的System.Runtime.Intrinsics.X86.Sse2.MoveMask ...

  8. 曲线艺术编程 coding curves 第九章 旋轮曲线(ROULETTE CURVES)

    第九章 旋轮曲线(ROULETTE CURVES) 原作:Keith Peters https://www.bit-101.com/blog/2022/11/coding-curves/ 译者:池中物 ...

  9. 前端vue单个文件上传支持图片,压缩包以及文件 , 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id=13066

    前端vue单个文件上传支持图片,压缩包以及文件 , 下载完整代码请访问uni-app插件市场址:https://ext.dcloud.net.cn/plugin?id=13066 效果图如下: 使用方 ...

  10. 曲线艺术编程 coding curves 第十二章 超级椭圆与超级方程(Superellipses and Superformulas)

    第十三章 超级椭圆与超级方程(Superellipses and Superformulas) 原作:Keith Peters https://www.bit-101.com/blog/2022/11 ...