hdu 5239__Doom
来源:互联网 发布:windows无法访问\\ 编辑:程序博客网 时间:2024/04/28 10:57
Doom
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 705 Accepted Submission(s): 171
Problem Description
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 ofn 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 thei -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 radixp , 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 froml -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.
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
There is a button on each cell. When the
Mike observes that the number is stored in radix
And now, Mike has got a list of operations. One operation is to push buttons between from
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 integersn,m (1≤n,m≤105 ).
The next line containsn integers ai (0≤ai<p ), which means the initial values of the n cells.
The nextm lines describe operations. In each line, there are two integers l,r(1≤l≤r≤n) , representing the operation.
For each test case, the first line contains two integers
The next line contains
The next
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.
For more details you can take a look at the example.
Sample Input
24 42 3 4 51 22 33 41 41 321 11 11 1
Sample Output
Case #1:51839405Case #2:2622
Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest
题意:一共有n个门,每个门都有一个权值,每次能打开从 l 到 r 的门,有个屏幕能在打开这些门之后把这些门里的值累计起来。每打开一扇门,这个门的权值就变为自身的平方。所有的值对p=9223372034707292160取余即是最后答案。
想法:利用线段树来更新区间的值并求和。看了题解才发现一个数自身平方到29次对p的取余就会不变。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=100000+100;typedef unsigned long long ll;const ll mod=9223372034707292160;ll sum[maxn<<2];int cnt[maxn<<2];void pushup(int rt){ sum[rt]=(sum[rt<<1]+sum[rt<<1|1])%mod; cnt[rt]=min(cnt[rt<<1],cnt[rt<<1|1]);}void build(int l,int r,int rt){ if(l==r) { scanf("%I64u",&sum[rt]); cnt[rt]=0; return ; } int m=(l+r)>>1; build(lson); build(rson); pushup(rt);}ll query(int L,int R,int l,int r,int rt){ if(L<=l&&r<=R) { return sum[rt]; } ll cnt=0; int m=(l+r)>>1; if(L<=m) cnt+=query(L,R,lson); if(cnt>mod) cnt-=mod; if(R>m) cnt+=query(L,R,rson); if(cnt>mod) cnt-=mod; return cnt;}ll quick_add(ll a,ll n){ if(n==0) return 0; ll sum=quick_add(a,n/2); sum=sum+sum; if(sum>=mod) sum-=mod; if(n&1) sum=sum+a; if(sum>=mod) sum-=mod; return sum;}void update(int L,int R,int l,int r,int rt){ if(cnt[rt]>=30) { return ; } if(l==r) { sum[rt]=quick_add(sum[rt],sum[rt]); cnt[rt]++; return ; } int m=(l+r)>>1; if(L<=m) { update(L,R,lson); } if(R>m) { update(L,R,rson); } pushup(rt);}int main(){ int T,L,R,n,m,cas=1; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); build(1,n,1); ll ans=0; printf("Case #%d:\n",cas++); for(int i=0;i<m;i++) { scanf("%d%d",&L,&R); ans+=query(L,R,1,n,1); if(ans>=mod) ans-=mod; printf("%I64u\n",ans); update(L,R,1,n,1); } } return 0;}
0 0
- hdu 5239__Doom
- HDU 5239 Doom
- hdu 5239 Doom
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- PHP学习(一)--认识PHP
- option selected index
- 【unity-Xcode】开发记录---备忘
- 2.2.3 Order-Independent Transparency (about order-independent blending) 顺序无关透明度(关于顺序无关的混合)
- Effective C++——条款22(第4章)
- hdu 5239__Doom
- Laravel5框架使用Oauth2.0
- Linux进程间通信——使用信号量
- 剑指Offer系列---(2)求链表中的倒数第k个结点
- hive报错FAILED: NullPointerException null原因
- 照明
- 数据结构--二叉树遍历
- AngularJS 应用身份认证的技巧
- 使用JDK自带jvisualvm监控tomcat