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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

2021年中国大学生程序设计竞赛 女生专场 - 热身赛 Problem C. 口算训练(质因子分解)

發布時間:2024/4/11 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2021年中国大学生程序设计竞赛 女生专场 - 热身赛 Problem C. 口算训练(质因子分解) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


題目分析:判斷 xxxyyy 的倍數,等價于質因子分解后, yyy 中的每個質因子的出現次數都小于等于其在 xxx 中的出現次數。

那么對于每次詢問 [l,r,d][l,r,d][l,r,d],實質上就是將 ddd 質因子分解后,判斷一下每個質因子在區間 [l,r][l,r][l,r] 中的出現次數。

問題轉換為了如何快速求解區間內某個質因子的出現次數。

因為本題的值域特別小,所以考慮按值域分塊,?100000?=316\lfloor \sqrt{100000} \rfloor=316?100000??=316

  • 小于等于 316316316 的質因子只有 656565 個,預處理出 656565 個前綴和暴力維護即可。
  • 大于 316316316 的質因子在 ddd 中至多出現一次,所以問題又轉換為了判斷區間存在問題。
  • 對于上面的第一種情況,暴力 O(n?65)O(n*65)O(n?65) 暴力維護即可;第二種情況的話也可以用二分輕松解決,時間復雜度 O(nlog?n)O(n\log n)O(nlogn),空間復雜度均攤下來是 O(n)O(n)O(n) 的。

    然后 ddd 的質因子至多有 log?d\log dlogd 個,所以對于每次詢問的復雜度就是 O(log?d+log?n)O(\log d+\log n)O(logd+logn)

    其實可以將本題帶修,前綴和改成線段樹,vector 改成 set,復雜度多一個 log?n\log nlogn 而已

    代碼:

    // #pragma GCC optimize(2) // #pragma GCC optimize("Ofast","inline","-ffast-math") // #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> #define lowbit(x) (x&-x) using namespace std; typedef long long LL; typedef unsigned long long ull; template<typename T> inline void read(T &x) {T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f; } template<typename T> inline void write(T x) {if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0'); } const int inf=0x3f3f3f3f; const int N=1e5+100; const int pcnt=65; const int pri[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313}; int sum[65][N]; vector<int>node[N]; int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);int w;cin>>w;while(w--) {memset(sum,0,sizeof(sum));for(int i=0;i<N;i++) {node[i].clear();}int n,m;read(n),read(m);for(int i=1;i<=n;i++) {int x;read(x);for(int j=0;j<pcnt;j++) {while(x%pri[j]==0) {x/=pri[j];sum[j][i]++;}}if(x>1) {node[x].push_back(i);}}for(int j=0;j<pcnt;j++) {for(int i=1;i<=n;i++) {sum[j][i]+=sum[j][i-1];}}while(m--) {int l,r,x;bool flag=true;read(l),read(r),read(x);for(int i=0;i<pcnt;i++) {if(x%pri[i]==0) {int cnt=0;while(x%pri[i]==0) {x/=pri[i];cnt++;}flag&=(sum[i][r]-sum[i][l-1])>=cnt;}}if(x>1) {int pos=*lower_bound(node[x].begin(),node[x].end(),l);if(pos>r) {flag=false;}}puts(flag?"Yes":"No");}}return 0; }

    總結

    以上是生活随笔為你收集整理的2021年中国大学生程序设计竞赛 女生专场 - 热身赛 Problem C. 口算训练(质因子分解)的全部內容,希望文章能夠幫你解決所遇到的問題。

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