Cattle off NOIP summer camp seven days - to improve the Group 5 HDU - 4676: Sum Of Gcd (Mo & team interval gcd equation) CodeForces - 645F: Cowslip Collections (number of combinations && Euler function)

A: ABS Deco's . Water problem,% first, then the number two adjacent min () about the difference.

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=10000000;
const int Mod=998244353;
int a[maxn]; ll ans;
int main()
{
    int N,D;
    scanf("%d%d",&N,&D);
    for(int i=1;i<=N;i++) scanf("%d",&a[i]),a[i]%=D;
    for(int i=2;i<=N;i++) {
        int t=abs(a[i]-a[i-1]);
        ans+=min(t,D-t);
    }
    printf("%lld\n",ans);
    return 0;
}

 

B: Deco the gcd . To give the array a [], the product of seeking twenty-two gcd.

Of course, if the sum of pairwise gcd is the inversion of the commonplace.

Did not do, you can refer to:

      HDU - 4676: Sum Of Gcd (Mo & team interval gcd equation) codeforces - 645 f: Cowslip the Collections (number of combinations && Euler function)      

1, but here it is the product of it irritated. We can multiply into a sum below and inversion.

2, from another point of view, due to the multiplication, and a multiplicative function, we considered separately for each prime number. For the same prime number p, its contribution is to take a min operation to determine the number of how many of each p, then the base and statistics about the prefix, you can count contributed. Note also Euler descending (I forgot the descending GG).

Its processing power of each prime number;

1, there are root algorithm, word complexity sqrt.

2, the pre-prime number within sqrt, 128 th. 128 words complexity;

3, when the prime number of the sieve smallest prime number for each record number P [i]. In addition it can always P [i], up to 1, the complexity of <18;

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=1000010;
const int Mod=998244353;
int vis[maxn],p[maxn],cnt,ans=1,K,P[maxn];
int qpow(int a,int x){
    int res=1; while(x){
        if(x&1) res=1LL*res*a%Mod;
        x>>=1; a=1LL*a*a%Mod;
    } return res;
}
void init()
{
    for(int i=2;i<maxn;i++){
        if(!vis[i]) p[++cnt]=i,Mn[i]=Mod,P[i]=i;
        for(int j=1;j<=cnt&&i*p[j]<maxn;j++){
            vis[i*p[j]]=1; P[i*p[j]]=p[j];
            if(!(i%p[j]))  break;
        }
    }
}
int G[maxn][20];
int main()
{
    int N,Q,x;
    init();
    scanf("%d",&N);
    rep(i,1,N) {
        scanf("%d",&x);
        while(x>1){
            int t=P[x],res=0;
            while(x%t==0) x/=t,G[t][++res]++;
        }
    }
    rep(i,1,cnt){
        int sum=0;
        for(int j=1;j<=18;j++){
            int t=G[p[i]][j];
            if(t<=1) break;
            (sum+=1LL*t*(t-1)/2%(Mod-1))%=(Mod-1);
        }
        ans=1LL*ans*qpow(p[i],sum)%Mod;
    }
    printf("%d\n",ans);
    return 0;
}

 

C: Deco's str

The meaning of problems: S val median number of cycles for each position corresponding intervals isomorphic = T, find val position and an adjacent plot.

Thinking: How to get the value for each location, if S is isomorphic cycle, the complexity will be higher. Therefore, considering T is isomorphic to M cycles, generating a new string of {M}, each new string appears recorded how many times, and for each position val = {} corresponding to the number of occurrences of the string . Then obviously you can do hash, for insurance, you can double hash.

#include<bits/stdc++.h>
#define ull unsigned long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=10000010;
const int Mod=1e9+7;
int seed=131; ull p[maxn],h[maxn],fcy;
char a[maxn],b[maxn]; int ans;
unordered_map<ull,int>mp;
ull gethash(int L,int R)
{
    return h[R]-h[L-1]*p[R-L+1];
}
int main()
{
    int N,M; scanf("%s%s",a+1,b+1);
    N=strlen(a+1); M=strlen(b+1);
    if(N<M*2) return puts("0"),0;
    p[0]=1; rep(i,1,N) p[i]=p[i-1]*seed;
    rep(i,1,N) h[i]=h[i-1]*seed+a[i]-'a'+1;
    rep(i,1,M) fcy=fcy*seed+b[i]-'a'+1;
    mp[fcy]++;
    rep(i,1,M) fcy=(fcy-(b[i]-'a'+1)*p[M-1])*seed+b[i]-'a'+1,mp[fcy]++;
    rep(i,1,N+1-M-M) {
        ull A=gethash(i,i+M-1),B=gethash(i+M,i+M+M-1);
        if(mp.find(A)==mp.end()) continue;
        if(mp.find(B)==mp.end()) continue;
        ans=ans+1LL*mp[A]*mp[B]%Mod;
        if(ans>=Mod) ans-=Mod;
    }
    printf("%d\n",ans);
    return 0;
}

 

 

 

Guess you like

Origin www.cnblogs.com/hua-dong/p/11404717.html