zoukankan      html  css  js  c++  java
  • Codeforces Round #705 (Div. 2)D. GCD of an Array (multiset)

    https://codeforces.com/contest/1493/problem/D

      1 #define IO std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
      2 #define bug(x) cout<<#x<<" is "<<x<<endl
      3 #include <bits/stdc++.h>
      4 #define iter ::iterator
      5 using namespace  std;
      6 typedef long long ll;
      7 typedef pair<int,ll>P;
      8 #define pb push_back
      9 #define mk make_pair
     10 #define se second
     11 #define fi first
     12 #define rs o*2+1
     13 #define ls o*2
     14 
     15 inline ll read(){ll x=0,f=1;char ch=getchar();  while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
     16 return x*f;}
     17 
     18 const ll mod=1e9+7;
     19 
     20 const int N=2e5+5;
     21 
     22 int T,n,cnt;
     23 
     24 ll ans=1;
     25 
     26 multiset<int>s[N];
     27 
     28 map<int,int>mp[N];
     29 
     30 ll qp(ll x,ll y){
     31     ll res=1;
     32     while(y){
     33         if(y&1)res=res*x%mod;
     34         x=x*x%mod;
     35         y>>=1;
     36     }
     37     return res;
     38 }
     39 
     40 void gao1(int id,int x,int y){
     41     if(!mp[id][x]){
     42         mp[id][x]=y;
     43         s[x].insert(y);
     44         if(s[x].size()==n){
     45             ans=ans*qp(x,*s[x].begin())%mod;
     46         }
     47         return;
     48     }
     49     if(s[x].size()==n){
     50         ll res=qp(x,*s[x].begin());
     51         ans=ans*qp(res,mod-2)%mod;
     52     }
     53     s[x].erase(s[x].find(mp[id][x]));
     54     mp[id][x]+=y;
     55     s[x].insert(mp[id][x]);
     56     if(s[x].size()==n){
     57         ans=ans*qp(x,*s[x].begin())%mod;
     58     }
     59 }
     60 
     61 void gao(int id,int x){
     62     int h=sqrt(x);
     63     for(int i=2;i<=h;i++){
     64         if(x%i)continue;
     65         ll tot=0;
     66         while(x%i==0){
     67             tot++;
     68             x/=i;
     69         }
     70         gao1(id,i,tot);
     71     }
     72     if(x>1)gao1(id,x,1);
     73 }
     74 
     75 int main(){ 
     76     n=read();T=read();
     77 
     78     for(int i=1;i<=n;i++){
     79         int x;
     80         x=read();
     81         gao(i,x);
     82     }
     83     while(T--){
     84         int id,x;
     85         id=read();
     86         x=read();
     87         gao(id,x);
     88         printf("%lld
    ",ans);
     89     }
     90 
     91 
     92 }
     93 /*
     94 
     95 8 24
     96 1 5 6 2 3 30 10 15
     97 8 2
     98 6 1
     99 4 3
    100 5 2
    101 2 6
    102 1 6
    103 
    104 
    105 
    106 */
  • 相关阅读:
    sp_trace_setfilter sqlserver筛选跟踪或跟踪过滤
    sp_trace_setevent sqlserver跟踪事件及列
    通过导入虚拟电脑的方式还原centos
    sqlserver profiler 抓出来作业的代码 SQLAgent
    克隆server2008R2造成SID冲突
    sqlserver ssms ctrl+e快捷键问题
    Caffe源码解析1:Blob
    梯度下降、随机梯度下降和批量梯度下降
    Caffe CNN特征可视化
    Caffe 抽取CNN网络特征 Python
  • 原文地址:https://www.cnblogs.com/ccsu-kid/p/14502521.html
Copyright © 2011-2022 走看看