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 这道题目测区间修改,但是不像加或减,开方不好处理,但是发现一个数开7 8次就变为1了,所以可以修改叶节点,然后求和就可以了。如果区间全是1,就不需要往下更新了
 #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define FO freopen("in.txt","r",stdin);
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << "&&" << x << "&&" << endl;
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a, b, sizeof(a));
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=;
const int inf = 0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head const int maxn=;
ll sum[maxn<<];
int n,q; void pushup(int rt) {
sum[rt]=sum[rt<<]+sum[rt<<|];
} void build(int rt,int L,int R) {
if(L==R) {
scanf("%lld",&sum[rt]);
return;
}
int mid=(L+R)>>;
build(rt<<,L,mid);
build(rt<<|,mid+,R);
pushup(rt);
} void updata(int rt,int L,int R,int l,int r) {
if(L==R) {
sum[rt]=sqrt(sum[rt]);
return;
}
if(L>=l&&R<=r&&sum[rt]==(R-L+)) return;
int mid=(L+R)>>;
if(l<=mid) updata(rt<<,L,mid,l,r);
if(r>mid) updata(rt<<|,mid+,R,l,r);
pushup(rt);
} ll query(int rt,int L,int R,int l,int r) {
if(L>=l&&R<=r) return sum[rt];
ll ans=;
int mid=(L+R)>>;
if(l<=mid) ans+=query(rt<<,L,mid,l,r);
if(r>mid) ans+=query(rt<<|,mid+,R,l,r);
pushup(rt);
return ans;
} int main() {
int cur=;
while(~scanf("%d",&n)) {
build(,,n);
scanf("%d",&q);
int op,ll,rr;
printf("Case #%d:\n",cur++);
while(q--) {
scanf("%d%d%d",&op,&ll,&rr);
int l=min(ll,rr),r=max(ll,rr);
if(op) printf("%lld\n",query(,,n,l,r));
else updata(,,n,l,r);
}
printf("\n");
}
}
												

最新文章

  1. ztreeDeptSelect 基于jquery和ztree的部门选择插件
  2. html表单样式, table隔行高亮, 长字符串自动换行
  3. HDU 1072(记忆化BFS)
  4. 4分钟apache自带ab压力测试工具使用: 2015.10.4
  5. background-clip,background-origin
  6. 查看Exchange邮件队列(queue)
  7. Java 期末复习提纲
  8. 【Java】JDBC连接MySQL
  9. 纯css3代码写下拉菜单效果
  10. 用户 IIS APPPOOL\DefaultAppPool 登录失败的解决方法
  11. 杭州电 1372 Knight Moves(全站搜索模板称号)
  12. OpenMP 入门教程
  13. Life in Changsha College-第一次冲刺
  14. Vxworks驱动程序的结构
  15. OSM数据下载地址
  16. ●POJ 2828 Buy Tickets
  17. Erlang的常驻模块与功能模块
  18. 并发库应用之十三 &amp; 并发集合类的应用
  19. 阿里云ssh断开处理办法
  20. 17 HTTP编程入门

热门文章

  1. paramiko 模块封装
  2. js笔试题一套(未完待续)
  3. Linux常用的编辑保存退出命令
  4. 部署和调优 2.9 mysql主从配置-3
  5. JDBC批处理数据
  6. [Python Study Notes]pandas.DataFrame.plot()函数绘图
  7. Emulator 模拟器起不来
  8. 关于TortoiseGit设置代理服务器会自动取消的问题解决方法
  9. nginx负载均衡, 配置地址带端口
  10. libmad介绍