[Examination reflection] 0420 provincial election simulation 75: An Zai

It seems that there is no outstanding performance, but I don't know why the ranking actually came up.

It may be that yesterday ’s holiday is today and everyone ’s status is relatively poor (passive skill: the effect of status reduction caused by staying up late is reduced by $ 65 \% $)

$ T1 $ is a seemingly intuitive question, and I thought of it along the first reaction.

The $ T2 $ push formula only thinks about half, and then optimizes $ n ^ 2log $ to $ O (n) $ to get $ 30 $ more. However, the special judgment is wrong and the $ 10 $ point is suspended.

$ T3 $ didn't get enough time left.

Okay. so sleepy.

 

T1: Bitcoin

General idea: Maintain multiple sets to support insertion, delete all values ​​equal to $ x $, all numbers $ + x $, and query how many binary $ k $ bits in the set are $ 1 $. $ k <18, n \ le 5 \ times 10 ^ 5, x \ le 10 ^ 9 $

When I saw that $ x $ was so big and $ k $ was so small, the first reaction was to take the modulus. The extra bits were obviously useless.

Found that the answer is only related to $ k $ and $ k $ is very small so we maintain the answer for each $ k $.

Directly get $ k $ tree arrays, each in the sense of modulo $ 2 ^ {i + 1} $, to query the weight sum of $ [2 ^ i, 2 ^ {i + 1}) $.

If all numbers are added, only one mark is needed globally. For multiple clearing, just use $ map $ to save the number of occurrences of each original number.

I mentally wrote a line tree. The writing is long and slow. Time complexity $ O (nk ^ 2) $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 map<ll,int>M;
 5 struct Segment_Tree{
 6     int w[1<<20],B;
 7     #define lc p<<1
 8     #define rc lc|1
 9     #define md (L+R>>1)
10     void add(int x,int v,int p,int L,int R){
11         w[p]+=v; if(L==R)return;
12         if(x<=md)add(x,v,lc,L,md);else add(x,v,rc,md+1,R);
13     }
14     int ask(int l,int r,int p,int L,int R){
15         if(l<=L&&R<=r)return w[p];
16         return (l<=md?ask(l,r,lc,L,md):0)+(r>md?ask(l,r,rc,md+1,R):0);
17     }
18     int ask(int l,int r){return l<=r?ask(l,r,1,0,B):ask(l,B,1,0,B)+ask(0,r,1,0,B);}
19     void add(int x,int v){add(x,v,1,0,B);}
20 }T[18];
21 int mo(ll x,int b){b=1<<b+1;return (x%b+b)%b;}
22 int main(){
23     for(int i=0;i<=17;++i)T[i].B=(1<<i+1)-1;
24     int n,op;ll x,tag=0;
25     cin>>n;
26     while(n--){
27         scanf("%d%lld",&op,&x);
28         if(op==0){
29             x-=tag;M[x]++;
30             for(int i=0;i<=17;++i)T[i].add(mo(x,i),1);
31         }else if(op==1){
32             x-=tag;int t=M[x];M[x]=0;
33             for(int i=0;i<=17;++i)T[i].add(mo(x,i),-t);
34         }else if(op==2)tag+=x;
35         else printf("%d\n",T[x].ask(mo((1<<x)-tag,x),mo((1<<x+1)-1- day, x)));
36      }
 37 }
View Code

 

T2: Test

大意:$\sum\limits_{i=1}^{A}\sum\limits_{j=1}^{B}\sum\limits_{k=1}^{C}d(ijk),A,B,C \le 10^5$

Enduring conclusion: $ d (nm) = \ sum \ limits_ {i | n} \ sum \ limits_ {j | m} [(i, j) = 1] $

The meaning is to consider the distribution of all factors. Because $ ij $ is required to be relatively prime, the factor must only be allocated on one side.

We believe that if there are $ x, y, a, b $ in the prime factors $ p $, $ n, m, i, j $, respectively.

Then if $ a = 0, b \ neq 0 $, then we think that the pair of $ (i, j) $ corresponds to a number with $ p ^ {x + b} $. Otherwise it corresponds to $ p ^ {a} $

In this way, all factors correspond to a $ (i, j) $.

This conclusion can be extended to the number of $ 3 $, which is $ d (xyz) = \ sum \ limits_ {i | x} \ sum \ limits_ {j | y} \ sum \ limits_ {k | z} [(i, j ) = 1] [(i, k) = 1] [(j, k) = 1] $

Then after some simple operations, the original problem will become: $ ans = \ sum \ limits_ {i = 1} ^ {A} \ frac {A} {i} \ sum \ limits_ {j = 1} ^ {B} \ frac {B} {j} \ sum \ limits_ {k = 1} ^ {C} \ frac {C} {k} [(i, j) = 1] [(i, k) = 1] [(j , k) = 1] $

莫反一下就是$\sum\limits_{d=1} \mu(d) \sum\limits_{z=1}^{C} \frac{C}{z} [(d,z)=1] \sum\limits_{x=1}^{\frac{A}{d}} \frac{A}{dx} [(x,z)=1] \sum\limits_{y=1}^{\frac{B}{d}} \frac{B}{dy} [(y,z)=1]$

Recursively handle the $ gcd $ relationship. This type of violence can do $ O (n ^ 2) $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define S 8001
 4 #define ui unsigned int
 5 bool g[S][S],np[S];int p[S],pc,mu[100005],A,B,C,oA[S],oB[S],cA,cB,rA[188],rB[188];
 6 ui G[100005],fA[S][188],fB[S][188],ans;
 7 vector<int>D[S];
 8 int main(){
 9     cin>>A>>B>>C;
10     mu[1]=1;
11     for(int i=2;i<S;++i){
12         if(!np[i])p[++pc]=i,mu[i]=-1;
13         for(int j=1;i*p[j]<S;++j)
14             if(i%p[j])np[i*p[j]]=1,mu[i*p[j]]=-mu[i];
15             else{np[i*p[j]]=1;break;}
16     }
17     for(int i=1;i<S;++i)for(int j=i;j<S;j+=i)D[j].push_back(i);
18     for(int i=1;i<S;++i)for(int j=1,I,l;I=i/j,j<=i;j=l+1)l=i/I,G[i]+=(l-j+1)*I; 
19     for(int i=A;i;--i)if(!oA[A/i])rA[oA[A/i]=++cA]=A/i;
20     for(int i=B;i;--i)if(!oB[B/i])rB[oB[B/i]=++cB]=B/i;
21     for(int i=2;i<=A&&i<=B;++i){
22         if(!np[i])for(int j=i;j<=C;j+=i)g[i][j]=1;
23         else{int x=D[i][1],y=i/x;for(int j=2;j<=C;++j)g[i][j]=g[x][j]|g[y][j];}
24     }
25     for(int z=1;z<=C;++z)for(int i=1;i<=cA;++i)for(int j=0;j<D[z].size();++j)fA[z][i]+=mu[D[z][j]]*G[rA[i]/D[z][j]];
26     for(int z=1;z<=C;++z)for(int i=1;i<=cB;++i)for(int j=0;j<D[z].size();++j)fB[z][i]+=mu[D[z][j]]*G[rB[i]/D[z][j]];
27     for(int d=1,a,b;a=oA[A/d],b=oB[B/d],d<=A&&d<=B;++d)if(mu[d])for(int z=1;z<=C;++z)if(!g[d][z])ans+=fA[z][a]*fB[z][b]*mu[d]*(C/z);
28     cout<<ans<<endl;
29 }
View Code

我们设$f_x(n)=\sum\limits_{i=1}^{n} [(i,x)=1] \mu(i),g_x(n)=\sum\limits_{i=1}^{n} [(i,x)=1] \frac{n}{i}$

则原式为$ans=\sum\limits_{x=1}^{A} \frac{A}{x} \sum\limits_{d=1}^{B} [(x,d)=1] \mu(d) g_x(\frac{B}{d}) g_x(\frac{C}{d})$

Enumerate $ x $, divide $ d $ into blocks, and use the defined $ f $ prefix and the difference to find the interval sum. If the latter can be preprocessed within the legal complexity, then the total complexity is $ O (n \ sqrt {n}) $

Consider how to preprocess $ f, g $: First of all, it is not difficult to find that for all $ x $, we adjust all the prime factors whose occurrence times exceed $ 1 $ to $ 1 $, and $ f, g $ are unchanged.

Then only need to consider the case where each qualitative factor contains only one. For a number $ x $, let its prime factor be $ p $

Because we know that $ (\ frac {p} {x}, x) = 1 $ without the square factor, we can directly consider the contribution of removing all multiples of the prime factor

Columnar simplification can get $ f_x (n) = f _ {\ frac {x} {p}} (n) + f_x (\ frac {n} {p}), g_x (n) = g _ {\ frac {x } {p}} (n) + g _ {\ frac {x} {p}} (\ frac {n} {p}) $

Then we can simply preprocess $ f_1 (n), g_1 (n) $

And all the $ n $ involved in the above are the numbers generated when dividing the block, there are $ O (\ sqrt {n}) $ in total.

So as long as all the values ​​involved in dividing the block are raised at the beginning, the above $ dp $ is done for these numbers.

However, it cannot survive, so we use search, adding a prime factor every time.

The total complexity is controlled at $ O (n \ sqrt {n}) $. The constant is a bit large.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ui unsigned int
 4 #define S 100001
 5 int p[S],pc,np[S],lp[S],ep[S],mu[S],_[S],c,v[S],A,B,C;
 6 ui sum[S],tot[S],ans,F[33][2333],G[33][2333];
 7 vector<int>pr;
 8 void sch(int x,int Lp,int d){
 9     for(int i=1,r;i<=B;i=r+1)r=min(B/(B/i),C/(C/i)),ans+=tot[x]*(F[d][_[r]]-F[d][_[i-1]])*G[d][_[B/i]]*G[d][_[C/i]];
10     for(int i=Lp,P;x*1ll*(P=pr[i])<=A;++i){
11         for(int j=1,n;n=v[j];++j)F[d+1][j]=F[d][j]+F[d+1][_[n/P]],G[d+1][j]=G[d][j]-G[d][_[n/P]];
12         sch(x*P,i+1,d+1);
13     }
14 }
15 int main(){
16     cin>>A>>B>>C; if(A>C)swap(A,C); if(A>B)swap(A,B); if(B>C)swap(B,C);
17     for(int i=2;i<=C;++i){
18         if(!np[i])p[++pc]=i,lp[i]=ep[i]=i,mu[i]=-1,pr.push_back(i);
19         for(int j=1,x;(x=i*p[j])<=C;++j)
20             if(i%p[j])lp[x]=p[j],ep[x]=ep[i]*p[j],mu[x]=-mu[i],np[x]=1;
21             else {lp[x]=p[j];np[x]=1;ep[x]=ep[i];break;}
22     }pr.push_back(C+1);
23     for(int i=lp[1]=ep[1]=mu[1]=1;i<=C;++i)mu[i]+=mu[i-1];
24     for(int x=1;x<=A;++x)tot[ep[x]]+=A/x;
25     for(int i=1,r,N;N=B/i,i<=B;i=r+1)r=B/N,v[++c]=N;
26     for(int i=1,r,N;N=C/i,i<=C;i=r+1)r=C/N,v[++c]=N;
27     sort(v+1,v+1+c); c=unique(v+1,v+1+c)-v-1;
28     for(int i=1;i<=c;++i){
29         _[v[i]]=i,F[0][i]=mu[v[i]],G[0][i]=sum[v[i]];
30         for(int j=1,N,r;N=v[i]/j,j<=v[i];j=r+1)r=v[i]/N,G[0][i]+=N*(r-j+1);
31     }sch(1,0,0); cout<<ans<<endl;
32 }
View Code

It seems that only I wrote the problem-solving method. The magical practice of $ LNC $ is smaller and you can see it.

 

T3: Light map

General idea: Find the sum of the $ k $ powers of the number of all connected blocks of the undirected graph with the $ n $ point. Test more. $ T \ le 10 ^ 5, n \ le 5 \ times 10 ^ 4, k \ le 15 $

Front: fft1 topic "Urban Planning". (This time I wrote a $ log $ polynomial inversion method, you can go back to the $ LNC $ Great God's blog)

After finding the number of all connected graphs with labels. Consider this question.

If the number of Unicom blocks is $ T $, then $ T ^ k = (1 + 1 + 1 + ... + 1) ^ k $. That is to say, from $ T $ and $ 1 $, you can select the number of plans for $ k $ times repeatedly.

We enumerate a few of them. $ ans = \ sum \ limits_ {i = 1} ^ {k} \ begin {bmatrix} k \\ i \ end {bmatrix} i! \ binom {T} {i} $

Take out $ T $ and consider the meaning in this way: we enumerate a set of $ i $ connected blocks. We consider how many graphs contain such collections.

First of all, we can find the number of graphs where we can find $ g_i (n) $ representing $ i $ connected blocks $ n $ points.

那么$ans=ans=\sum\limits_{i=1}^{k} \begin{bmatrix} k \\ i \end{bmatrix} i! \sum\limits_{j=1}^{n} g_i(j) 2^{\binom{n-j}{2}} \binom{n}{j}$

That is, select a number of points to form a specific shape as an enumerated set of connected blocks, and the remaining parts are randomly connected.

In this way, a single inquiry can be answered with $ O (k) $.

The only question left is how to find $ g $. First, $ g_1 $ is "Urban Planning"

$g_t(x) = g_1(i) g_{t-1}(x-i) \binom{x-1}{i-1}$

The number of combinations is a certain.

The total time complexity is $ O (knlogn) $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define mod 1004535809
 4 #define S 262144
 5 int rev[S],r[S],n,A[S],B[S],fac[S],inv[S],G0[S],G1[S],F[16][S],FR[S],s[16][16],E[16][S],len,pw[S];
 6 int mo(int x){return x>=mod?x-mod:x;}
 7 int qp(int b,int t,int a=1){for(;t;t>>=1,b=1ll*b*b%mod)if(t&1)a=1ll*a*b%mod;return a;}
 8 void NTT(int*a,int op=1){
 9     for(int i=1;i<len;++i)if(rev[i]>i)swap(a[i],a[rev[i]]);
10     for(int i=1;i<len;i<<=1)for(int j=0,w=qp(3,(mod-1)/2/i*op+mod-1);j<len;j+=i<<1)
11         for(int k=j,x,y,t=1;k<j+i;++k,t=1ll*t*w%mod)
12             x=a[k],y=a[k+i]*1ll*t%mod,a[k]=mo(x+y),a[k+i]=mo(x-y+mod);
13     if(op-1)for(int iv=qp(len,mod-2),i=0;i<len;++i)a[i]=1ll*a[i]*iv%mod;
14 }
15 void sat(int n){
16     len=1; while(len<=n)len<<=1;
17     for(int i=1;i<len;++i)rev[i]=rev[i>>1]>>1|(i&1?len>>1:0);
18 }
19 void Inv(int*a,int n){
20     if(n==1){r[0]=qp(a[0],mod-2);return;}
21     Inv(a,n+1>>1); sat(n<<1);
22     for(int i=0;i<len;++i)A[i]=i<n?a[i]:0;
23     for(int i=0;i<len;++i)B[i]=r[i];
24     NTT(A);NTT(B);
25     for(int i=0;i<len;++i)r[i]=(B[i]+B[i]-1ll*B[i]*A[i]%mod*B[i]%mod+mod)%mod;
26     NTT(r,-1);
27     for(int i=n+1;i<len;++i)r[i]=0;
28 }
29 int main(){
30     for(int i=0;i<=50000;++i)pw[i]=qp(2,i*(i-1ll)/2);
31     s[0][0]=1;
32     for(int i=1;i<=15;++i)for(int j=1;j<=i;++j)s[i][j]=(s[i-1][j-1]+1ll*s[i-1][j]*j)%mod;
33     for(int i=fac[0]=1;i<=50000;++i)fac[i]=fac[i-1]*1ll*i%mod;
34     inv[50000]=qp(fac[50000],mod-2);
35     for(int i=49999;~i;--i)inv[i]=inv[i+1]*(i+1ll)%mod;
36     for(int i=0;i<=50000;++i)G1[i]=pw[i]*1ll*inv[i]%mod,G0[i]=pw[i]*1ll*(i?inv[i-1]:0)%mod;
37     Inv(G1,50001);sat(100000); NTT(r); NTT(G0);
38     for(int i=0;i<len;++i)FR[i]=1ll*G0[i]*r[i]%mod; NTT(FR,-1); FR[0]=0;
39     for(int i=0;i<len;++i)F[1][i]=1ll*FR[i]*fac[i-1]%mod;
40     for(int i=50001;i<len;++i)FR[i]=0;
41     NTT(FR);
42     for(int t=2;t<=15;++t){
43         for(int i=0;i<len;++i)A[i]=0;
44         for(int i=1;i<=50000;++i)A[i]=F[t-1][i]*1ll*inv[i]%mod;
45         NTT(A); for(int i=0;i<len;++i)A[i]=1ll*A[i]*FR[i]%mod; NTT(A,-1);
46         for(int i=1;i<=50000;++i)F[t][i]=A[i]*1ll*fac[i-1]%mod;
47     }
48     for(int t=1;t<=15;++t){
49         for(int i=0;i<len;++i)A[i]=B[i]=0;
50         for(int i=0;i<=50000;++i)A[i]=pw[i]*1ll*inv[i]%mod,B[i]=F[t][i]*1ll*inv[i]%mod;
51         NTT(A);  NTT(B); for(int i=0;i<len;++i)E[t][i]=A[i]*1ll*B[i]%mod; NTT(E[t],-1);
52         for(int i=0;i<len;++i)E[t][i]=1ll*E[t][i]*fac[i]%mod;
53     }
54     int t,n,k,ans;cin>>t;while(t--){
55         ans=0;scanf("%d%d",&n,&k);
56         if(!k){puts("1");continue;}
57         for(int i=1;i<=k;++i)ans=(ans+1ll*s[k][i]*fac[i]%mod*E[i][n])%mod;
58         printf("%lld\n",ans*1ll*qp(pw[n],mod-2)%mod);
59     }
60 }
View Code

 

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/12741272.html