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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

HDU 5239 上海大都会 D题(线段树+数论)

發布時間:2025/7/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 5239 上海大都会 D题(线段树+数论) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

打表,發現規律是存在一定次數(較小)后,會出現a=(a*a)%p。可以明顯地發現本題與線段樹有關。設置標記flag,記錄本段內的數是否均已a=a*a%p。若是,則不需更新,否則更新有葉子結點,再pushup。

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define LL unsigned long long using namespace std; const LL p=9223372034707292160uLL; const int N=100050; int n; LL seg[N<<2],s; bool flag[N<<2];void build(int rt,int l,int r){flag[rt]=false;if(l==r){scanf("%llu",&seg[rt]);// cout<<l<<"="<<seg[rt]<<endl;return ;}int m=(l+r)>>1;build(rt<<1,l,m);build(rt<<1|1,m+1,r);seg[rt]=(seg[rt<<1]+seg[rt<<1|1])%p; }LL mul(LL a,LL b){LL res=0;while(b){if(b&1) res=(res+a)%p;b>>=1;a=(a+a)%p;}return res; }void update(int rt,int l,int r,int L,int R){if(flag[rt]&&l<=L&&R<=r){s=(s+seg[rt])%p;return ;}if(L==R){s=(s+seg[rt])%p;LL tmp=mul(seg[rt],seg[rt]);if(seg[rt]==tmp){flag[rt]=true;}seg[rt]=tmp;return ;}int m=(L+R)>>1;if(r<=m){update(rt<<1,l,r,L,m);}else if(l>=m+1) update(rt<<1|1,l,r,m+1,R);else{update(rt<<1,l,r,L,m);update(rt<<1|1,l,r,m+1,R);}flag[rt]=flag[rt<<1]&flag[rt<<1|1];seg[rt]=(seg[rt<<1]+seg[rt<<1|1])%p; }int main(){int T,icase=0,k,l,r;scanf("%d",&T);while(T--){s=0;scanf("%d%d",&n,&k);build(1,1,n);printf("Case #%d:\n",++icase);for(int i=1;i<=k;i++){scanf("%d%d",&l,&r);update(1,l,r,1,n);printf("%llu\n",s);}}return 0; }

  

轉載于:https://www.cnblogs.com/jie-dcai/p/4539908.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的HDU 5239 上海大都会 D题(线段树+数论)的全部內容,希望文章能夠幫你解決所遇到的問題。

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