[examination reflection] 0520 provincial simulation 101: Purpose

Posted by Tsukiyomi on Fri, 05 Jun 2020 04:56:42 +0200

No need to say. Why is it such a dish.

You don't need to think about $60 of $T1.

(well, what did I do in this exam?

$T2 $looks like a $min25 $sieve board. It's just that there's a lot of data

However, because I seldom met the question of $min25 $, I only wrote it once and it was three months ago.

So basically, I forgot to try to think about it in the exam room.

As a result, I finally finished my work in the dark. After losing the samples, I handed them in.

Very happy is: take a model. Direct zero. And then it's gone.

It's just like practicing unskilled knowledge...

I don't know what I'm trying to do. I wish I could stop being mentally retarded in the exam room

 

T1: stone game

Main idea: $nim $. Ask to get rid of at least a few piles of stones to win first. $n \le 5 \times 10^5,A \le 5 \times 10^5$

It is required to use at least how many heaps to get the same XOR value as all stone heaps.

The number of stone piles deleted is $logA $level. Otherwise, if the linear basis can be expressed, it can be removed.

So violence to do $dp $is $O(n^2) $. Each round of optimization with $xorFWT $can achieve $O(nlog^2n) $. Using the essence of $FWT $to find a single point value can achieve $O(nlogn)$

 1 #include<cstdio>
 2 #define S 1<<19
 3 int a[S],n,t[S],T,ans;
 4 void FWT(int*a){for(int i=1;i<S;i<<=1)for(int j=0;j<S;j+=i<<1)for(int k=j,x,y;k<j+i;++k)x=a[k],y=a[k+i],a[k]=x+y,a[k+i]=x-y;}
 5 int main(){
 6     scanf("%d",&n);n++;
 7     for(int i=1,x;i<n;++i)scanf("%d",&x),T^=x,t[x]=1;
 8     a[T]=1; FWT(t);
 9     while(n--,!a[0]){FWT(a);for(int i=0;i<S;++i)a[i]=a[i]*t[i];FWT(a);for(int i=0;i<S;++i)a[i]=a[i]?1:0;}
10     printf("%d\n",n);
11 }
View Code

 

T2: function

Main idea: $f (P ^ E) = P ^ k, f (a b) = f (a) f (b) ((a, b) = 1) $. Find $\ sum\limits_{i=1}^{n} f(i)$. $n \le 10^{13},k \le 20$

Send the $min25 $template.

 1 #include<cstdio>
 2 #include<cmath>
 3 #define ll long long
 4 #define mod 1000000007
 5 const int S=12345678,s=3333333;
 6 ll n,v[S];int k,iv[23],st[23][23],g0[s],g1[s],p[S],pc,vc,sq,f[s],pre[s]; bool np[S];
 7 int&g(ll x){return x<=sq?g0[x]:g1[n/x];}
 8 int mo(int x){return x>=mod?x-mod:x;}
 9 int spw(ll n,int k,int a=0){n%=mod;for(int i=0,C=n+1;i<=k;++i)a=(a+1ll*st[k][i]*C%mod*iv[i+1])%mod,C=C*1ll*(n-i)%mod;return a;}
10 int pw(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;}
11 int Sum(ll n,int c,int a=0){
12     if(p[c]>n||n<=1)return 0;
13     for(int z=c;z<=pc&&1ll*p[z]*p[z]<=n;++z)
14         for(ll t=p[z];1ll*t*p[z]<=n;t*=p[z])a=(a+f[p[z]]*(1ll+Sum(n/t,z+1)))%mod;
15     return mo(a+mo(g(n)-pre[c-1]+mod));
16 }
17 int main(){
18     scanf("%lld%d",&n,&k);
19     st[0][0]=iv[1]=1; sq=sqrt(n);
20     for(int i=1;i<=k;++i)for(int j=1;j<=i;++j)st[i][j]=(st[i-1][j]*1ll*j+st[i-1][j-1])%mod;
21     for(int i=2;i<23;++i)iv[i]=mod-mod/i*1ll*iv[mod%i]%mod;
22     
23     f[1]=pre[0]=1;
24     for(int i=2;i<=sq;++i){
25         if(!np[i])p[++pc]=i,f[i]=pw(i,k),pre[pc]=mo(pre[pc-1]+f[i]);
26         for(int j=1,x;(x=i*p[j])<=sq;++j){
27             np[x]=1; f[x]=f[i]*f[p[j]];
28             if(i%p[j]==0){f[x]=f[i];break;}
29         }
30     }
31     for(ll i=1,r,N;N=n/i,i<=n;i=r+1)r=n/N,v[++vc]=N;
32     for(int i=1;i<=vc;++i)g(v[i])=spw(v[i],k)-(!k);
33     for(int i=1;i<=pc;++i)for(int j=1;1ll*p[i]*p[i]<=v[j];++j)g(v[j])=(g(v[j])-1ll*(g(v[j]/p[i])-pre[i-1])*f[p[i]]%mod+mod)%mod;
34     printf("%d\n",mo(Sum(n,1)+1+mod));
35 }
View Code

We construct a $g(x)=x^k $. Try designing a $h $so that $f=g*h $. It's the Dirichlet convolution.

$f(1)=g(1)h(1)$. So there's $h(1)=1$

$f(p)=g(p)h(1)+h(p)g(1)$. So there's $h(p)=0$

Go ahead and have $h(p^e)=p^e-p^{2e} $. Of course, $h $is also a product function.

Then we know that $h $only has value at $powerfull \ number $.

Set $G(n)=\sum\limits_{i=1}^{n} g(i)$. It's a natural number power sum that can be calculated by $O(k) $

$\sum\limits_{i=1}^{n} f(i) =\sum\limits_{j=1}^{n} \sum\limits_{d|i}g(d)h(\frac{n}{i})$

$=\sum\limits_{i=1}^{n} h(i) \sum\limits_{j=1}^{\frac{n}{i}} j$

$=\sum\limits_{i=1}^{n} h(i) G(\frac{n}{i})$

Pop up all $powerful \ number $(each search must find one, and the total number is $\ sqrt{n} $). For each $powerful \ number$, calculate a corresponding $G$, which is the sum of powers of natural numbers

Complexity $O(k\sqrt{n}) $. It may be a bit stuck, and the sum of natural number powers can be memorized.

 1 #include<cstdio>
 2 #include<cmath>
 3 #define ll long long
 4 const int S=10000007,mod=1000000007;
 5 ll n;int k,iv[23],st[23][23],p[S],pc,sq,h[S]; bool np[S];
 6 int spw(int n,int a=0){for(int i=0,C=n+1;i<=k;++i)a=(a+1ll*st[k][i]*C%mod*iv[i+1])%mod,C=C*1ll*(n-i)%mod;return a;}
 7 int pw(int b,int t=k,int a=1){for(;t;t>>=1,b=1ll*b*b%mod)if(t&1)a=1ll*a*b%mod;return a;}
 8 struct hash_map{
 9     int fir[S],l[S],v[S],ec;ll to[S];
10     int&operator[](ll x){int r=x%S;
11         for(int i=fir[r];i;i=l[i])if(to[i]==x)return v[i];
12         l[++ec]=fir[r];fir[r]=ec;to[ec]=x;return v[ec]=spw(x%mod);
13     }
14 }M;
15 int Sum(ll n,int hp,int c,int a=0){
16     for(int z=c;z<=pc;++z){
17         ll t=n/p[z]/p[z]; if(!t)break; int Hp=hp*1ll*h[p[z]]%mod;
18         for(;t;t/=p[z])a=(a+Sum(t,Hp,z+1))%mod;
19     }return (a+1ll*hp*M[n])%mod;
20 }
21 int main(){
22     scanf("%lld%d",&n,&k);
23     st[0][0]=iv[1]=1; sq=sqrt(n);
24     for(int i=1;i<=k;++i)for(int j=1;j<=i;++j)st[i][j]=(st[i-1][j]*1ll*j+st[i-1][j-1])%mod;
25     for(int i=2;i<23;++i)iv[i]=mod-mod/i*1ll*iv[mod%i]%mod;
26     for(int i=2;i<=sq;++i){
27         if(!np[i])p[++pc]=i,h[i]=pw(i)-pw(1ll*i*i%mod),h[i]+=h[i]<0?mod:0;
28         for(int j=1,x;(x=i*p[j])<=sq;++j){np[x]=1;if(i%p[j]==0)break;}
29     }printf("%d",Sum(n,1,1));
30 }
View Code

 

T3: Painting

Figure, the weight of $I $per point is in $[0,limit_i]$. The weights of two adjacent points with edges are different. The sum of all points is the given value of $C $. $n \le 15,limit,C \le 10^{18}$

Consider that there is no edge. It feels like a digit of $dp $.

We consider bit by bit, and force all numbers on the higher order of the currently considered bit to be close to the upper bound (if the upper bound does not match the high order of $C $, we will directly jump out)

Set $dp[i][0/1][0/1] $to indicate whether the number of the first $I $is considered and whether the number is off the upper bound. The current consideration bit is $1 $or $0 $.

This can be easily transferred. $dp[n][1][bit(C,x)] $is the answer. Complexity is $O(n\times logC)$

Then consider the case of a small number of sides. It's not hard to think of tolerance and exclusion, and enumeration of the edges that meet the conditions. The result of subset inversion shows that the inclusion exclusion coefficient is the power of the size of the edge set of $- 1 $.

Consider optimization. There are some redundant states in this idea, for example, $1-2, $2-3 $are the same but $1-3 $is different. This is clearly illegal.

So we enumerate a point set. The coefficient of the point set is the sum of the tolerance and exclusion coefficients of all the connected and exported subgraphs in the current point set.

That is to say, every time a point set is forced to be the same color, different point sets are not limited to be calculated.

This coefficient can be obtained by subtracting the whole set illegally. Enumerate the connected blocks of the $1 $point each time. Since the sum of positive and negative combinations is $0 $, we can know that the sum of inclusion exclusion coefficients of all derived subgraphs (not necessarily connected) of all subsets with edges is $0 $, otherwise, $1 $.

This is a good way to move. Let $dp[i][j] $indicate that the currently selected point set is $I $, the exclusive or of all global points and the exclusive or sum of all points of $j $set.

Consider how to get $j $: if the size of a connected block is even, then the contribution to global exclusive or is $0 $. If it's an odd number, it depends on the minimum point of $limit $.

We know that $j $must be a subset of $i $. The number of States is $n^3 $. The specified minimum point must be included in the transition, enumerating the subset of the complement.

Because there is a point with the largest $limit $in the current point set $j $, there must be no $2 $to the right of it. This is $\ sum 3^i 2^{n-i} $. It's still $3^n $. So complexity is right.

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define ll long long
 4 #define mod 998244353
 5 #define S 1<<15
 6 int n,m,ie[S],ans,c[S],bit[S],pw[S],t23[S],dp[55555555],mnp[S]; ll a[16],C;
 7 void mo(int&x){if(x>=mod)x-=mod;}
 8 int&T(int s,int t){return dp[t23[s]+t23[t]];}
 9 #define any (1ll<<i)
10 #define lim ((a[j]&any-1)+1)
11 int ask(int s,int A=0){
12     static int dp[16][2][2];dp[0][0][0]=1;
13     for(int i=59,c;c=0,~i;--i){
14         for(int j=1;j<=n;++j){
15             if(s>>j-1&1^1){for(int x=0;x<2;++x)for(int y=0;y<2;++y)dp[j][x][y]=dp[j-1][x][y];continue;}
16             dp[j][0][0]=dp[j][0][1]=dp[j][1][0]=dp[j][1][1]=0;
17             for(int x=0;x<2;++x)for(int y=0;y<2;++y)
18                 if(a[j]>>i&1)mo(dp[j][1][y]+=dp[j-1][x][y]*(x?any%mod:1)%mod),mo(dp[j][x][y^1]+=dp[j-1][x][y]*(lim%mod)%mod);
19                 else mo(dp[j][x][y]+=dp[j-1][x][y]*(lim%mod)%mod);
20             c^=a[j]>>i&1;
21         }mo(A+=dp[n][1][C>>i&1]); if(C>>i&1^c)break;else A+=!i;
22     }return A;
23 }
24 int main(){
25     scanf("%d%d%lld",&n,&m,&C); a[0]=2e18;
26     for(int i=1;i<=n;++i)scanf("%lld",&a[i]),mnp[1<<i-1]=i;
27     for(int i=1,x,y;i<=m;++i){
28         scanf("%d%d",&x,&y);
29         for(int j=0;j<1<<n;++j)if(j&1<<x-1&&j&1<<y-1)ie[j]=1;
30     }
31     for(int i=1;i<1<<n;++i)bit[i]=bit[i^i&-i]^1,mnp[i]=i^i&-i?(mnp[i&-i^(a[mnp[i^i&-i]]<a[mnp[i&-i]]?i:0)]):mnp[i];
32     for(int i=pw[0]=1;i<n;++i)pw[i]=pw[i-1]*3;
33     for(int i=0;i<1<<n;++i)for(int j=0;j<n;++j)if(i>>j&1)t23[i]+=pw[j];
34     for(int i=1;i<1<<n;++i){
35         int x=i&-i;c[i]=!ie[i];
36         for(int j=i-1&i;j;j=j-1&i)if(j&x&&!ie[i^j])mo(c[i]+=mod-c[j]);
37     }
38     dp[0]=1; int U=(1<<n)-1; 
39     for(int i=0;i<=U;++i)for(int j=i,l=!j;l<2;j=j-1&i,l+=l+!j)if(T(i,j))for(int e=U^i,r=e;r;r=r-1&e)if((e&-e)==(r&-r))
40         if(bit[r])mo(T(i|r,j|1<<mnp[r]-1)+=1ll*T(i,j)*c[r]%mod);
41         else mo(T(i|r,j)+=1ll*T(i,j)*c[r]%mod*((a[mnp[r]]+1)%mod)%mod);
42     for(int i=0;i<1<<n;++i)if(T(U,i))mo(ans+=1ll*ask(i)*T(U,i)%mod);
43     printf("%d",ans);
44 }
View Code

Topics: IE