Number Theory Series solution to a problem of cancer xgzc

A hay pendulum
  that Italy: having a 1 to n are arranged, q recitations, each section gives the minimum value of l ~ r a, Q a first previous number of contradictory statements.
  \ (1 \ leq n \ leq
10 ^ 6, q \ leq 25000 \)   Solution: binary answer. If a large section of the intersection contains a certain small range and a certain set is contradictory.
  Relationship can comprise disjoint-set or segment tree(Disjoint-set true cancer ah)
  Segment tree small talk. If disjoint-set, then [l, r] is covered by the force directed to the parent node interval r + 1. If find (l)> r it proves interval is covered over.(Good metaphysics ah) (Can be shared equally demonstrated little complexity from xgzc)
  Complexity: \ (O (Q \ Q * log \ Alpha (n-)) \)

#include<bits/stdc++.h>
using namespace std;
#define maxn 25005
struct Query
{
    int l,r,v;
    inline friend bool operator < (Query a,Query b)
        {
            return a.v>b.v;
        }
}query[maxn],tmp[maxn];
int fa[1000005],n;
inline int findf(int x)
{
    return (fa[x]==x)?x:(fa[x]=findf(fa[x]));
}
bool check(int x)
{
    for(int i=1;i<=x;++i) tmp[i]=query[i];
    for(int i=1;i<=n+1;++i) fa[i]=i;
    sort(tmp+1,tmp+x+1);
    int l1,l2,r1,r2;
    l1=l2=tmp[1].l,r1=r2=tmp[1].r;
    for(int i=2;i<=x;++i)
    {
        if(tmp[i].v<tmp[i-1].v)
        {
            if(findf(l1)>r1) return false;
            for(int j=fa[l2];j<=r2;j=fa[j])
            {
                findf(j);
                fa[j]=findf(j+1);
            }
            l1=l2=tmp[i].l,r1=r2=tmp[i].r;
        }
        else
        {
            l1=max(l1,tmp[i].l),l2=min(l2,tmp[i].l);
            r1=min(r1,tmp[i].r),r2=max(r2,tmp[i].r);
            if(r1<l1) return false;
        }
    }
    if(findf(l1)>r1) return false;
    return true;
}
int main()
{
    freopen("bales.in","r",stdin),freopen("bales.out","w",stdout);
    int q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=q;++i)
        scanf("%d%d%d",&query[i].l,&query[i].r,&query[i].v);
    int l=1,r=q+1,mid;
    while(l<r)
    {
        mid=(l+r)>>1;
        if(check(mid)) l=mid+1;
        else r=mid;
    }
    printf("%d\n",l>q?0:l);
    return 0;
}

  B saber
  title meaning: given \ (n * m \) trellis diagram, \ (Y = X +. 1 \) an upper left point not go all (available online) only upwards or to the right, from Q (0, 0) to (n, m) digital to analog 19999999 path section. \ (2 \ leq m \ leq
n \ leq 10 ^ {10} \)   Solution: Program number considered illegal. Obviously all such paths, can be line \ (y = x \ + 2 ) along the outer path from the lower right to the upper left of the fold, i.e. from (0,0) to (m-2, n + 2 ) of Scheme number. So \ (ans = C_ {n +
m} ^ {m} -C_ {n + m} ^ {m-2} \)   due to the smaller modulus to the lucas.
  Complexity: \ (O (MOD) \)

#include<bits/stdc++.h>
using namespace std;
#define mod 19999999
#define ll long long
ll inv[mod+5],fac[mod+5];
inline void exgcd(ll a,ll b,ll& x,ll& y)
{
    if(!b)
    {
        x=1,y=0;
        return;
    }
    exgcd(b,a%b,y,x);
    y-=a/b*x;
}
inline void pre(int x)
{
    inv[0]=fac[0]=1;
    for(int i=1;i<=x;++i)
        fac[i]=fac[i-1]*i%mod;
    ll tx,ty;
    exgcd(fac[x],mod,tx,ty);
    inv[x]=(tx%mod+mod)%mod;
    for(int i=x-1;i;--i)
        inv[i]=(i+1)*inv[i+1]%mod;
}
inline ll c(ll x,ll y)
{
    return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
inline ll lucas(ll x,ll y)
{
    return c(x%mod,y%mod)*c(x/mod,y/mod)%mod;
}
int main()
{
    freopen("saber.in","r",stdin),freopen("saber.out","w",stdout);
    int n,m;
    scanf("%d%d",&n,&m);
    pre((n+m+2)%mod);
    printf("%lld\n",(lucas(n+m,m)-lucas(n+m,m-2)+mod)%mod);
    return 0;
}

  C was not good enough
  that Italy: Long brush to a question. He will not do it.
  Given n, find
  \ [\ sum_ {i = 1 } ^ {n} \ sum_ {j = 1} ^ {n} \ sum_ {k = 1} ^ {n} {[j \ mid i] [(j + k) \ mid i]}
\ mod 998244353 \]   wherein \ ([x] \) represents the value is true if x is 1 or 0. \ (n \ leq 10 7 \
^)   Solution: Obviously \ (ans = \ sum_ {i = 1} ^ {n} {\ frac {d (i) ^ 2-d (i)} {2}} \) , where d is a function of the number of factors.
  Linear screen can be.
  Complexity: \ (O (n-) \)

#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
#define maxn 10000005
int n,vis[maxn],id[maxn],num[maxn],prime[1000005],cnt;
inline void eular(int x)
{
    int tmp;
    for(int i=2;i<=x;++i)
    {
        if(!vis[i]) prime[++cnt]=i,id[i]=2,num[i]=1;
        for(int j=1;j<=cnt&&i*prime[j]<=x;++j)
        {
            tmp=i*prime[j];
            vis[tmp]=1;
            if(i%prime[j])
            {
                id[tmp]=2*id[i];
                num[tmp]=1;
            }
            else
            {
                id[tmp]=id[i]*(num[i]+2)/(num[i]+1);
                num[tmp]=num[i]+1;
                break;
            }
        }
    }
}
int main()
{
    freopen("good.in","r",stdin),freopen("good.out","w",stdout);
    scanf("%d",&n);
    eular(n+2);
    long long ans=0;
    int tmp;
    for(int i=1;i<=n;++i)
    {
        tmp=id[i];
        ans+=((tmp*tmp-tmp)>>1)%mod;
        ans%=mod;
    }
    printf("%lld\n",ans);
    return 0;
}

  D muffled large fortune
  that Italy: Long and hyj game do problems. There are n-1-question number 2 ~ n. Each question can only be done by one person (or no one did). Long and hyj demand from doing any questions were selected two numbers are not prime to the number of programs. Two people can not question. Program number of modulo p. \ (n \ leq 500, p
\ leq 10 ^ 9 \)   Solution: Pressure-like \ (\ sqrt n \) prime number within the set. Set \ (dp [i] [j ] \) represents the number of dragon selected from the set of prime factors of i, hyj is selected from the group j. In this way (might) be left a large prime number. Set \ (f1 [i] [j ] [k], f2 [i] [j] [k] \) represents the i-th selected from, two sets of programs are a number of candidates j, k, large prime numbers .
  Two arrays initial value dp.
  Transfer to \ (F1 [I] [J \ S MID] [K] + = F1 [I] [J] [K] (S \ & K == 0) \) . Another empathy.
  \ (ans = \ sum_ {i
= 0} \ sum_ {j = 0} {dp [i] [j]} \)   Note i want to roll out, otherwise MLE.
  Complexity: \ (O (n-2 * 2 ^ ^ *. 8. 8) \) (since the ratio of \ (\ sqrt n \) smaller first prime number 19, 8)

#include<bits/stdc++.h>
using namespace std;
struct Num
{
    int s,num;
    inline friend bool operator < (Num a,Num b)
        {
            if(a.num==b.num) return a.s<b.s;
            return a.num<b.num;
        }
}num[505];
int prime[9]={0,2,3,5,7,11,13,17,19};
int n,p,dp[257][257],tmp[2][257][257],ans;
inline void add(int& a,const int& b)
{
    a=(a+b)%p;
}
int main()
{
    freopen("rich.in","r",stdin),freopen("rich.out","w",stdout);
    scanf("%d%d",&n,&p);
    int tn;
    for(int i=2;i<=n;++i)
    {
        tn=i;
        for(int j=1;j<=8;++j)
        {
            if(tn%prime[j]) continue;
            num[i].s|=(1<<(j-1));
            while(!(tn%prime[j])) tn/=prime[j];
        }
        num[i].num=tn;
    }
    sort(num+2,num+n+1);
    dp[0][0]=1;
    for(int i=2;i<=n;++i)
    {
        if(i==2||num[i].num==1||num[i].num xor num[i-1].num)
            memcpy(tmp[1],dp,sizeof(dp)),memcpy(tmp[0],dp,sizeof(dp));
        for(int j=255;j>=0;--j)
            for(int k=255;k>=0;--k)
            {
                if(!(k&num[i].s)) add(tmp[0][j|num[i].s][k],tmp[0][j][k]);
                if(!(j&num[i].s)) add(tmp[1][j][k|num[i].s],tmp[1][j][k]);
            }
        if(i==n||num[i].num==1||num[i].num xor num[i+1].num)
            for(int j=0;j<=255;++j)
                for(int k=0;k<=255;++k)
                    dp[j][k]=((tmp[0][j][k]+tmp[1][j][k]-dp[j][k])%p+p)%p;
    }
    for(int i=255;i>=0;--i)
        for(int j=255;j>=0;--j)
            if(!(i&j)) add(ans,dp[i][j]);
    printf("%d\n",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/123789456ye/p/11521400.html