THE END IS COMINGGGGGG!

Mike has got stuck on a mystery machine. If he cannot solve this problem, he will go to his doom.

This machine is consist of n cells, and a screen. The i-th cell contains a number ai(1≤i≤n). The screen also contains a number s, which is initially 0.

There is a button on each cell. When the i-th is pushed, Mike observes that, the number on the screen will be changed to s+ai, where s is the original number. and the number on the i-th cell will be changed to a2i.

Mike observes that the number is stored in radix p, where p=9223372034707292160. In other words , the operation is under modulo p.

And now, Mike has got a list of operations. One operation is to push buttons between from l-th to r-th (both included), and record the number on the screen. He is tired of this stupid work, so he asks for your help. Can you tell him, what are the numbers recorded.

Input
The first line contains an integer T(T≤5), denoting the number of test cases.

For each test case, the first line contains two integers n,m(1≤n,m≤105).

The next line contains n integers ai(0≤ai<p), which means the initial values of the n cells.

The next m lines describe operations. In each line, there are two integers l,r(1≤l≤r≤n), representing the operation.

Output
For each test case, output ‘‘Case #t:’’, to represent this is the t-th case. And then output the answer for each query operation, one answer in a line.

For more details you can take a look at the example.
Sample Input
2
4 4
2 3 4 5
1 2
2 3
3 4
1 4
1 3
2
1 1
1 1
1 1
Sample Output
Case #1:
5
18
39
405
Case #2:
2
6
22
给出n个数和m个操作,每个操作给出l和r,求出l到r的和来后,就把l到r之间的数都平方。每次输出的结果都加上之前的结果。。
打表找规律,不断模上那个数之后将近三十次之后,就不会变了。这样就不会一直更新。设一个flag标记一下就行。注意要用unsigned long long,并且在平方的时候注意用快速乘。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<string>
#define ll unsigned long long
using namespace std;const int maxx=1e5+100;
const ll mod=9223372034707292160;
struct node{int l;int r;ll v;bool flag;
}p[maxx<<2];
int n,m;
ll ans;inline ll qsj(ll x,ll y)
{ll ans1=0;while(y){if(y&1) ans1=(ans1+x)%mod;x=(x+x)%mod;y>>=1;}return ans1%mod;
}
inline void pushup(int cur)
{p[cur].flag=p[cur<<1].flag&p[cur<<1|1].flag;p[cur].v=(p[cur<<1].v+p[cur<<1|1].v)%mod;
}
inline void build(int l,int r,int cur)
{p[cur].l=l;p[cur].r=r;p[cur].flag=0;if(l==r){scanf("%lld",&p[cur].v);return ;}int mid=(l+r)>>1;build(l,mid,cur<<1);build(mid+1,r,cur<<1|1);pushup(cur);
}
inline void update(int l,int r,int cur)
{if(p[cur].flag) return ;int L=p[cur].l;int R=p[cur].r;if(L==R){ll s=p[cur].v;p[cur].v=qsj(p[cur].v,p[cur].v);if(s==p[cur].v) p[cur].flag=1;return ;}int mid=(L+R)>>1;if(r<=mid) update(l,r,cur<<1);else if(l>mid) update(l,r,cur<<1|1);else {update(l,mid,cur<<1);update(mid+1,r,cur<<1|1);}pushup(cur);
}
inline ll query(int l,int r,int cur)
{int L=p[cur].l;int R=p[cur].r;if(l<=L&&R<=r){return p[cur].v%mod;}int mid=(L+R)>>1;if(r<=mid) return query(l,r,cur<<1)%mod;else if(l>mid) return query(l,r,cur<<1|1)%mod;else return (query(l,mid,cur<<1)+query(mid+1,r,cur<<1|1))%mod;pushup(cur);
}int main()
{int t,k=0;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);build(1,n,1);int x,y;ans=0;printf("Case #%d:\n",++k);while(m--){scanf("%d%d",&x,&y);if(x>y) swap(x,y); printf("%lld\n",(ans=(ans+query(x,y,1))%mod));update(x,y,1);}}return 0;
}

努力加油a啊,(o)/~

Doom HDU - 5239(线段树+思维)相关推荐

  1. POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新

    直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...

  2. 线段树——思维(Codeforces 339D Xenia and Bit Operations/Billboard HDU - 2795)

    Codeforces 339D Xenia and Bit Operations vj地址 题意:给出2的n次方个数,每次将现在这个序列中相邻的两个数运算后合并为一个数,得到一个新的序列,这个新序列的 ...

  3. hdu 4747 mex 线段树+思维

    http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意: 我们定义mex(l,r)表示一个序列a[l]....a[r]中没有出现过得最小的非负整数, 然后我 ...

  4. HDU - 6602 Longest Subarray(线段树+思维)

    题目链接:点击查看 题目大意:给出一个长度为 n 的序列,每个数字的范围是 [ 1 , C ] ,现在需要求一个子串,使得字串中的字母,要么出现 0 次,要么出现至少 K 次,问这个子串的最大长度是多 ...

  5. HDU - 6315 Naive Operations(线段树+思维)

    题目链接:点击查看 题目大意:给出一个数列 a 和一个数列 b ,其中数列 a 初始时全部为 0 ,数列 b 初始时是一个 1 ~ n 的排列,接下来共有 m 次操作,每次操作分为两种: add l ...

  6. HDU - 6992 Lawn of the Dead 线段树 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一张n∗mn*mn∗m的图,其中有kkk个点不能走,你只能向下和向右走,问你能到达多少点. n,m,k≤1e5n,m,k\le1e5n,m,k≤1e5 思 ...

  7. hdu 5367(线段树+区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5367 官方题解: 对于求"高山脉"长度,可以利用线段树.树节点中保存左高度连续长度 ...

  8. hdu 5266(线段树+LCA)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5266 解题思路: 考虑dfs序,通过在简单的证明可知L~R的LCA为L ~R 中dfs序较小的那个位置 ...

  9. hdu 5124(线段树区间更新+lazy思想)

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 题意:区间覆盖次数问题. 解题思路:线段树水之. #include<iostream> #in ...

  10. HDU - 4578Transformation——线段树+区间加法修改+区间乘法修改+区间置数+区间和查询+区间平方和查询+区间立方和查询

    [题目描述] HDU - 4578Transformation Problem Description Yuanfang is puzzled with the question below: The ...

最新文章

  1. PHP时间戳 strtotime()使用方法和技巧
  2. knn计算机在图片中的应用,图像分类和kNN
  3. 湖南对口升学计算机组装考点,全国计算机等级考试湖南省考点名单及联系方式...
  4. matlab stk 代码,STK与matlab互联,stkSetPropClassical报错
  5. 最后一个单词的长度Python解法
  6. md5加密工具类_贼好用的 Java 工具类库! GitHub 星标 10k+,你在用吗?
  7. 今日恐慌与贪婪指数为91 贪婪程度有所缓解
  8. python基础篇——函数
  9. c语言求圆锥的表面积和体积_C语言-圆形体体积计算器,1:计算球体;2:计算圆柱体;3:计算圆锥体...
  10. 世界上最大的计算机硬盘,全球最大机械硬盘:8碟12TB、充氦封装
  11. Android新手入门 FAQ
  12. Docker学习之六:基于Dockerfile构建镜像
  13. DHPST分销系统-EP分销-云主机分销系统
  14. 1026. 多米诺和三格骨牌铺瓦问题
  15. Proteus仿真STM32F103R6(一)
  16. SQL-多表关联查询详解
  17. LiteOS | 基于LiteOS的智慧农业案例实验分享
  18. MyBatis从删库到跑路
  19. FFMPEG常用的一些命令介绍:音频录制、视频录制
  20. JAVA计算机毕业设计实验室耗材管理系统源码+系统+mysql数据库+lw文档

热门文章

  1. logo是啥_乐夏2开播,33支乐队的Logo设计,凭啥一个塑料袋最火?
  2. 程序员基本功11树和二叉树
  3. mysql特有语法_MySQL详细的基础语法
  4. python randrange函数_Python学习-函数补充2-内置函数
  5. python head 函数_python爬虫中header是什么?怎么用?
  6. Android开发之播放量点赞量打赏量收藏量单位格式化工具类
  7. 计算机io接口指令控制,计算机接口及IO指令.ppt
  8. 在Matlab命令窗口中执行,交互式命令操作就是在MATLAB命令行窗口中输入命令并执行。...
  9. 设计模式-模版方法模式
  10. 如何开启一个Django项目