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

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

2017CCPC 杭州 J. Master of GCD【差分标记/线段树/GCD】

發(fā)布時(shí)間:2024/1/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2017CCPC 杭州 J. Master of GCD【差分标记/线段树/GCD】 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

給你一個(gè)n個(gè)初始元素都為1的序列和m個(gè)詢(xún)問(wèn)q。
詢(xún)問(wèn)格式為:l r x(x為2or3)
最后求1~n所有數(shù)的GCD
GCD:把每個(gè)數(shù)分別分解質(zhì)因數(shù),再把各數(shù)中的全部公有質(zhì)因數(shù)提取出來(lái)連乘,所得的積就是這幾個(gè)數(shù)的最大公約數(shù)。

#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #include<algorithm> #include<vector> #include<map> #include<cctype> #include<stack> #include<sstream> #include<list> #include<assert.h> #include<bitset> #include<numeric> #define debug() puts("++++") #define gcd(a,b) __gcd(a,b) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define fi first #define se second #define pb push_back #define sqr(x) ((x)*(x)) #define ms(a,b) memset(a,b,sizeof(a)) #define sz size() #define be begin() #define pu push_up #define pd push_down #define cl clear() #define lowbit(x) -x&x #define all 1,n,1 #define mod 998244353#define pi acos(-1.0) #define rep(i,x,n) for(int i=(x); i<(n); i++) using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> P; const int INF = 1<<30; const int maxn = 1e5+3; const double eps = 1e-8; const int dx[] = {-1,1,0,0,1,1,-1,-1}; const int dy[] = {0,0,1,-1,1,-1,1,-1}; int dir[2]={-1,1}; const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; LL t,n,m; LL Pow(LL a, LL b) {LL res=1;while(b){if(b&1)res=(res%mod * a%mod)%mod;a = a%mod*a%mod;b>>=1;}return res%mod; } LL a[maxn],b[maxn]; int main() {scanf("%lld",&t);while(t--){ms(a,0),ms(b,0);scanf("%lld%lld",&n,&m);while(m--){LL l,r,x;scanf("%lld%lld%lld",&l,&r,&x);if(x==2){a[l]++,a[r+1]--; //差分標(biāo)記因子含有2的數(shù)、區(qū)間加維護(hù)2or3的操作數(shù)}else{b[l]++,b[r+1]--;}}LL m1=a[1],m2=b[1];for(int i=2;i<=n;i++){a[i]+=a[i-1]; //前綴和維護(hù)序列本身,而序列記錄2的操作數(shù)即個(gè)數(shù),得到具體每個(gè)數(shù)的操作數(shù)b[i]+=b[i-1];m1=min(m1,a[i]); //2的最小操作數(shù)m2=min(m2,b[i]);}LL ans = (Pow(2,m1)%mod*Pow(3,m2)%mod)%mod;printf("%lld\n",ans);} } /* 2 5 3 1 3 2 3 5 2 1 5 3 6 3 1 2 2 5 6 2 1 6 26 2 【題意】【類(lèi)型】【分析】【時(shí)間復(fù)雜度&&優(yōu)化】【trick】【數(shù)據(jù)】*/

轉(zhuǎn)載于:https://www.cnblogs.com/Roni-i/p/9527250.html

總結(jié)

以上是生活随笔為你收集整理的2017CCPC 杭州 J. Master of GCD【差分标记/线段树/GCD】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。