日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Doom HDU - 5239(线段树+思维)

發布時間:2023/12/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Doom HDU - 5239(线段树+思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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(线段树+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。