hdu 4027 Can you answer these queries?
来源:互联网 发布:淘宝客户维护方案 编辑:程序博客网 时间:2024/05/16 16:57
Can you answer these queries?
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 11760 Accepted Submission(s): 2770
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.
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.
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.
Sample Input
101 2 3 4 5 6 7 8 9 1050 1 101 1 101 1 50 5 81 4 8Sample Output
Case #1:1976
/*hdu 4027 Can you answer these queries?0:对[l,r]的数取平方根1:求[l,r]的和由于0操作是取平方根,感觉不适合于标记下传,但是如果对于每个都更新到节点的话太费时间,而且可以发现2^64最多8次就变成1了,而且对于1去平方根不变,所以在单点更新的基础上判断区间是否全为1即可hhh-2016-03-29 15:17:46*/#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<math.h>#include<functional>using namespace std;#define lson (i<<1)#define rson ((i<<1)|1)typedef long long ll;const int maxn = 100500 ;struct node{ int l,r; ll sum; int mid() { return (l+r)>>1; }} tree[maxn<<2];void push_up(int i){ tree[i].sum=tree[lson].sum+tree[rson].sum;}void build(int i,int l,int r){ tree[i].l = l, tree[i].r = r; tree[i].sum = 0; if(l == r) { scanf("%I64d",&tree[i].sum); return ; } int mid = tree[i].mid(); build(lson,l,mid); build(rson,mid+1,r); push_up(i);}void push_down(int i){}void update(int i,int l,int r){ if(tree[i].l == tree[i].r) { tree[i].sum = sqrt(tree[i].sum*1.0); return; } if(tree[i].l >= l && tree[i].r <= r) { if(tree[i].sum == tree[i].r-tree[i].l+1) return ; } if(l <= tree[i].mid()) update(lson,l,r); if(r > tree[i].mid()) update(rson,l,r); push_up(i);}ll query(int i,int l,int r){ if(tree[i].l >= l && tree[i].r <= r) return tree[i].sum; ll ans = 0; push_down(i); if(l <= tree[i].mid()) ans += query(lson,l,r); if(r > tree[i].mid()) ans += query(rson,l,r); return ans;}int main(){ int cas = 1,n; while(scanf("%d",&n) != EOF) { build(1,1,n); printf("Case #%d:\n", cas++); int q,x,y,op; scanf("%d",&q); while(q--) { scanf("%d",&op); if(op == 0) { scanf("%d%d",&x,&y); if(x > y)swap(x,y); update(1,x,y); } if(op == 1) { scanf("%d%d",&x,&y); if(x > y)swap(x,y); printf("%I64d\n",query(1,x,y)); } } printf("\n"); } return 0 ;}
0 0
- HDU--4027(Can you answer these queries?)
- HDU-4027-Can you answer these queries
- hdu 4027 Can you answer these queries?
- HDU-4027-Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- HDU--4027(Can you answer these queries?)
- hdu - 4027 Can you answer these queries?
- hdu-4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- hdu-4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- 适配器习题(设计模式)
- ccf 高速公路(连通子图)
- iOS 一个类似QQ的图片添加、图片浏览Demo
- C++第二次作业
- iOS 中button的用法
- hdu 4027 Can you answer these queries?
- 1005 banknotes
- 一道String面试题
- Android MediaPlayer 音乐播放
- 2010年哈尔滨工业大学计算机研究生机试真题
- Android Handler Memory Leak
- hdu 4052 线段树扫描线、奇特处理
- Clone使用方法详解
- Android Studio安装过程以及导入eclipse工程遇到的问题