Doom
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 426 Accepted Submission(s): 96
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 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.
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.
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.
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
思路:比赛的时候压根没有时间做这个题,赛后发现这个mod是一个特殊的数,任何数平方几次后对他取余就不会再变了,然后就是线段树区间更新了,可以收先处理处搜有的结果,也可以暴力更新,因为只要更新30次
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<climits>
#include<algorithm>
using namespace std;
typedef unsigned long long LL;
const int maxn=100010;
const int maxm=30;
const LL MOD=9223372034707292160LL;
LL a[maxn];
int N,M;
LL pow_mul(LL x,LL y)
{
LL res=0;
while(y)
{
if(y&1)res=(res+x)%MOD;
y>>=1;
x=(x+x)%MOD;
}
return res;
}
struct IntervalTree
{
LL sum[maxn<<2][30];
int setv[maxn<<2];
void build(int o,int l,int r)
{
setv[o]=0;
if(l==r)
{
sum[o][0]=a[l];//cout<<sum[o][0]<<endl;
for(int i=1;i<maxm;i++)
{
sum[o][i]=pow_mul(sum[o][i-1],sum[o][i-1]);
//cout<<sum[o][i]<<endl;
}
return ;
}
int mid=(l+r)>>1;
build(o<<1,l,mid);
build(o<<1|1,mid+1,r);
pushup(o);
}
void pushup(int o)
{
for(int i=0;i<maxm;i++)
sum[o][i]=(sum[o<<1][i]+sum[o<<1|1][i])%MOD;
}
LL query(int o,int l,int r,int q1,int q2)
{
if(q1<=l&&r<=q2)
{
return sum[o][0];
}
pushdown(o);
int mid=(l+r)>>1;
LL ans=0;
if(q1<=mid)ans=(ans+query(o<<1,l,mid,q1,q2))%MOD;
if(q2>mid)ans=(ans+query(o<<1|1,mid+1,r,q1,q2))%MOD;
pushup(o);
return ans;
}
void maintain(int o,int k)
{
for(int j=0;j<maxm-1;j++)
sum[o][j]=sum[o][min(j+k,maxm-1)];
}
void pushdown(int o)
{
if(setv[o])
{
setv[o<<1]+=setv[o];
setv[o<<1|1]+=setv[o];
maintain(o<<1,setv[o]);
maintain(o<<1|1,setv[o]);
setv[o]=0;
}
}
void update(int o,int l,int r,int q1,int q2)
{
if(q1<=l&r<=q2)
{
setv[o]+=1;
maintain(o,1);
return ;
}
pushdown(o);
int mid=(l+r)>>1;
if(q1<=mid)update(o<<1,l,mid,q1,q2);
if(q2>mid)update(o<<1|1,mid+1,r,q1,q2);
pushup(o);
}
}tree;
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&N,&M);
for(int i=1;i<=N;i++)
scanf("%I64u",&a[i]);
tree.build(1,1,N);
LL ans=0;
printf("Case #%d:\n",cas++);
while(M--)
{
int l,r;
scanf("%d%d",&l,&r);
ans=(ans+tree.query(1,1,N,l,r))%MOD;
tree.update(1,1,N,l,r);
cout<<(ans%MOD)<<endl;
}
}
return 0;
}
这个题解中是直接暴力更新的
http://blog.youkuaiyun.com/zava_1087/article/details/46040747