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.

InputThe 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 2
63.

  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.

OutputFor 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.Sample Input

10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8

Sample Output

Case #1:
19
7
6

这道题太坑了了了了了了了。。。。。。。。。。。

1、你需要用long long

2、为啥我看题目上说的是四舍五入,但是实际操作四舍五入结果都不对,卧槽。。。。。。。

3、对于输入数据你还要判断他给的那个区间,左边节点是不是小于或等于右边节点。。。。这真是让人无语

4、开数组要开题目上N的四倍

5、那个对1、0开方特别慢,所以要特判,,,

注意:不要对区间开方,是对单个点开方,所以区间里面的数最小值应该等于该区间长度

上代码:

 1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<math.h>
5 #include<algorithm>
6 #include<queue>
7 #include<stack>
8 #include<vector>
9 using namespace std;
10 #define lson l,m,rt<<1
11 #define rson m+1,r,rt<<1|1
12 const int INF=0x3f3f3f3f;
13 const int maxn=100005;
14 typedef long long ll;
15 ll sum[maxn<<2];
16 void pushup(ll rt)
17 {
18 sum[rt]=sum[rt<<1]+sum[rt<<1|1];
19 }
20 void build(ll l,ll r,ll rt)
21 {
22 if(l==r)
23 {
24 scanf("%lld",&sum[rt]);
25 return;
26 }
27 ll m=(l+r)>>1;
28 build(l,m,rt<<1);
29 build(m+1,r,rt<<1|1);
30 pushup(rt);
31 }
32 void update(ll L,ll R,ll l,ll r,ll rt)
33 {
34 if(sum[rt]==r-l+1) return ;
35 //if(sum[rt]==1 || sum[rt]==0) return;
36 //里面数为0、1的时候就不用递归了,这两个数开方特别慢
37 if(l==r)
38 {
39 sum[rt]=(ll)sqrt(sum[rt]);
40 //n=(int)sqrt((double)x);
41 //sqrt()函数,里面的形参是double型的,所以调用的时候,要强制转换成double型。
42 return;
43 }
44 ll m=(l+r)>>1;
45 if(L<=m) update(L,R,l,m,rt<<1);
46 if(R>m) update(L,R,m+1,r,rt<<1|1);
47 pushup(rt);
48 }
49 ll query(ll L,ll R,ll l,ll r,ll rt)
50 {
51 if(l>=L && R>=r)
52 {
53 return sum[rt];
54 }
55 ll m=(l+r)>>1;
56 ll ans=0;
57 if(L<=m) ans+=query(L,R,l,m,rt<<1);
58 if(R>m) ans+=query(L,R,m+1,r,rt<<1|1);
59 return ans;
60 }
61 int main()
62 {
63 int n,m,k=0;
64 while(~scanf("%d",&n))
65 {
66 memset(sum,0,sizeof(sum));
67 k++;
68 printf("Case #%d:\n",k);
69 build(1,n,1);
70 scanf("%d",&m);
71
72 while(m--)
73 {
74 int x,y,z;
75 scanf("%d%d%d",&x,&y,&z);
76 if(z < y)
77 {
78 y = y+z;
79 z = y-z;
80 y = y-z;
81 }
82 if(x==0)
83 {
84 update(y,z,1,n,1);
85 }
86 else
87 {
88 printf("%lld\n",query(y,z,1,n,1));
89 }
90 }
91 printf("\n");
92 }
93 return 0;
94 }

输入:

Output

每次x=1时,每行一个整数,表示这次旅行的开心度

Sample Input4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

Sample Output101

11

11

Hint

对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9

这道题和上一道题真是绝配呀。。。。。。。

这个开方和上一道题一样,就是特判哪里不对,因为他是向下取整所以那个开方出来的数据可能为0,所以要另外开一个数组充当标记,当这个父节点的左右子节点都为1、0的时候才可以跳过去

上代码:

 1 //要开方,而且不能用sum[rt]==r-l+1来判断因为向下取整可能会出现0
2 //此时我想说一句:“你好骚呀!”
3 /* ***********************************************
4 ┆ ┏┓   ┏┓ ┆
5 ┆┏┛┻━━━┛┻┓ ┆
6 ┆┃       ┃ ┆
7 ┆┃   ━   ┃ ┆
8 ┆┃ ┳┛ ┗┳ ┃ ┆
9 ┆┃       ┃ ┆
10 ┆┃   ┻   ┃ ┆
11 ┆┗━┓ 马 ┏━┛ ┆
12 ┆  ┃ 勒 ┃  ┆      
13 ┆  ┃ 戈 ┗━━━┓ ┆
14 ┆  ┃ 壁     ┣┓┆
15 ┆  ┃ 的草泥马  ┏┛┆
16 ┆  ┗┓┓┏━┳┓┏┛ ┆
17 ┆   ┃┫┫ ┃┫┫ ┆
18 ┆   ┗┻┛ ┗┻┛ ┆
19 ************************************************ */
20 #include<stdio.h>
21 #include<string.h>
22 #include<iostream>
23 #include<math.h>
24 #include<algorithm>
25 #include<queue>
26 #include<stack>
27 #include<vector>
28 using namespace std;
29 #define lson l,m,rt<<1
30 #define rson m+1,r,rt<<1|1
31 const int INF=0x3f3f3f3f;
32 const int maxn=100005;
33 typedef long long ll;
34 ll sum[maxn<<2],flag[maxn<<2];
35 void pushup(ll rt)
36 {
37 sum[rt]=sum[rt<<1]+sum[rt<<1|1];
38 flag[rt]=flag[rt<<1]&&flag[rt<<1|1];
39 }
40 void build(ll l,ll r,ll rt)
41 {
42 if(l==r)
43 {
44 scanf("%lld",&sum[rt]);
45 return;
46 }
47 ll m=(l+r)>>1;
48 build(l,m,rt<<1);
49 build(m+1,r,rt<<1|1);
50 pushup(rt);
51 }
52 void update(ll L,ll R,ll l,ll r,ll rt)
53 {
54 if(flag[rt]) return ;
55 //if(sum[rt]==1 || sum[rt]==0) return;
56 //里面数为0、1的时候就不用递归了,这两个数开方特别慢
57 if(l==r)
58 {
59 sum[rt]=floor(sqrt(sum[rt]));//这个floor函数加不加都行
60 if(sum[rt]<=1) flag[rt]=1;
61 //n=(int)sqrt((double)x);
62 //sqrt()函数,里面的形参是double型的,所以调用的时候,要强制转换成double型。
63 return;
64 }
65 ll m=(l+r)>>1;
66 if(L<=m) update(L,R,l,m,rt<<1);
67 if(R>m) update(L,R,m+1,r,rt<<1|1);
68 pushup(rt);
69 }
70 ll query(ll L,ll R,ll l,ll r,ll rt)
71 {
72 if(l>=L && R>=r)
73 {
74 return sum[rt];
75 }
76 ll m=(l+r)>>1;
77 ll ans=0;
78 if(L<=m) ans+=query(L,R,l,m,rt<<1);
79 if(R>m) ans+=query(L,R,m+1,r,rt<<1|1);
80 return ans;
81 }
82 int main(){
83 int n;
84 scanf("%d",&n);
85 build(1,n,1);
86 int m;
87 scanf("%d",&m);
88 while(m--){
89 int x,l,r;
90 scanf("%d %d %d",&x,&l,&r);
91 if(x==2)update(l,r,1,n,1);
92 else printf("%lld\n",query(l,r,1,n,1));
93 }
94 return 0;
95 }

G - Can you answer these queries? & N - 花神游历各国的更多相关文章

  1. GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)

    GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...

  2. BZOJ-3211花神游历各国 并查集+树状数组

    一开始想写线段树区间开方,简单暴力下,但觉得变成复杂度稍高,懒惰了,编了个复杂度简单的 3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MB Subm ...

  3. BZOJ 3211: 花神游历各国( 线段树 )

    线段树...区间开方...明显是要处理到叶节点的 之前在CF做过道区间取模...差不多, 只有开方, 那么每个数开方次数也是有限的(0,1时就会停止), 最大的数10^9开方10+次也就不会动了.那么 ...

  4. BZOJ 3211: 花神游历各国【线段树区间开方问题】

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 3514  Solved: 1306[Submit][Status][Discu ...

  5. bzoj3211花神游历各国 线段树

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 4252  Solved: 1547[Submit][Status][Discu ...

  6. 【BZOJ】【3211】花神游历各国

    线段树/暴力 线段树区间开方 唉,我傻逼了一下,TLE了一发,因为没考虑到0的情况…… 好吧简单来说一下,线段树动态查询区间和大家都会做……比较麻烦的是这次的修改变成开方了,然而这并没有什么好虚的,注 ...

  7. BZOJ3211: 花神游历各国(线段树)

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 5692  Solved: 2114[Submit][Status][Discu ...

  8. 【BZOJ3211】花神游历各国 并查集+树状数组

    [BZOJ3211]花神游历各国 Description Input Output 每次x=1时,每行一个整数,表示这次旅行的开心度 Sample Input 41 100 5 551 1 22 1 ...

  9. [BZOJ3211]花神游历各国&&[BZOJ3038] 上帝造题的七分钟2 树状数组+并查集

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 4057  Solved: 1480[Submit][Status][Discu ...

随机推荐

  1. If you see someone without smile

    If you see someone without smile, give them one of yours. 难怪我每次和不认识的人说话都放肆大笑.

  2. Centos 6 下安装 OSSEC-2.8.1 (一)

    ossec -2.8.1 安装: ## 1 ) 安装依赖包: RedHat / Centos / Fedora / Amazon Linux yum install -y pcre mysql mys ...

  3. 【IMP】IMP导入表的时候,如果表存在怎么办

    在imp导入的时候,如果表存在的话,会追加数据在表中, 所以如果不想追加在表中的话,需要将想导入的表truncate掉后,在imp SQL: truncate table TEST1; imp tes ...

  4. 小试牛刀ElasticSearch大数据聚合统计

    ElasticSearch相信有不少朋友都了解,即使没有了解过它那相信对ELK也有所认识E即是ElasticSearch.ElasticSearch最开始更多用于检索,作为一搜索的集群产品简单易用绝对 ...

  5. DB2版本升级(V9.7升级到V11.1)

    1.V11.1版本升级路线 DB2 11.1 可以将现有的 Db2 V9.7.Db2 V10.1 或 Db2 V10.5 实例和数据库直接升级到 Db2 V11.1.如果 Db2 服务器正在 Db2 ...

  6. [Usaco2008 Mar]River Crossing渡河问题

    题目描述 Farmer John以及他的N(1 <= N <= 2,500)头奶牛打算过一条河,但他们所有的渡河工具,仅仅是一个木筏. 由于奶牛不会划船,在整个渡河过程中,FJ必须始终在木 ...

  7. PAT练习num1-害死人补偿命的3n+1猜想

    卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 ( 砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在 1950 年的世界 ...

  8. ProBuilder快速原型开发技术 ---ProBuilder基础操作

    在游戏开发.虚拟现实等三维仿真领域,Unity目前是国内外最为知名的开发引擎.随着版本的不断提升与完善,目前Unity2020等最新版本,又增加了很多令人惊奇的功能. Unity内置的ProBuild ...

  9. Kubernetes调整Node节点快速驱逐pod的时间

    在高可用的k8s集群中,当Node节点挂掉,kubelet无法提供工作的时候,pod将会自动调度到其他的节点上去,而调度到节点上的时间需要我们慎重考量,因为它决定了生产的稳定性.可靠性,更快的迁移可以 ...

  10. JavaScript中的异步函数

    JavaScript中的异步函数 ES8 的 async/await 旨在解决利用异步结构组织代码的问题.为此, ECMAScript 对函数进行了扩展,为其增加了两个新关键字: async 和 aw ...