[Exam reflection] 0219 provincial election simulation 26: Precision

The first accurate Gufen. Three questions and Gufen are exactly the same.

If this is a good thing to say. . .

I would be the point estimate is too low

Modiu wronged points naturally is a good thing, but also points to finish wronged Modiu so low to be justified.

Time allocation is determined and the degree of difficulty and some errors, the term $ T1 / 3 $ + tub family wants polynomial generating function.

Then nausea themselves up. Then $ T2 $ looks like a large data structure nausea, the results do not know where to put the time in.

T3 $ relatively simple and basically had no time to think of leaving. The entire division is also no higher reason.

 

T1: Coloring Problem

Effect: $ n $ long sequence, $ m $ colors sequentially transfected a non-empty continuum, averages the last number of each location has a different sequence of colors. $ N, m \ le 10 ^ 6 $

Good question.

Followed by dyeing a little trouble, pour sake, each dyed a continuously empty intervals where undyed, for the first time can not be empty.

It's $ dp $. After the number of programs provided $ $ i $ J $ wheel position as well as undyed, the $ dp_ {i, j} = dp_ {i-1, j} + (j + 1) \ sum \ limits_ {k = j + 1} $ ^ {n} dp_ {i-1, k} $

Prefix and optimization of violence can get points.

Transfer is very strange. The first part is a $ 1 $ coefficient, the location is not a dye, similar to transmission.

The second is the number of solutions to stain all cases multiply the $ (j + 1) $. After staining is the number of remaining blank space $ 1 + $, similar to the end result of the transfer process.

That is, for each (which appeared in color) program, its contribution to the end result is the product of the number, and not settled the number of restrictions.

So we actually occurred last enumeration $ i $ colors, a number of combinations (note that the last necessarily occur), then the quest is (optional $ i $ a foothold in the product) and.

In the form of a bit like a backpack. So we designed a similar thing generating function, the end result of an article into them

(But this size is 1 for the convenience of the program we put on the constant, the final index also reversed over)

I.e. $ \ prod \ limits_ {i = 2} ^ {n} (x + i) $. It's $ i $ coefficient is the number of times the program $ ni $ colors (the end result) of.

Consider how this thing seek. The first and most simple and crude is the partition $ FFT $. Time complexity $ O (nlog ^ 2n) $. 80 can be obtained.

However, this is more than a lot of. . . Your partition when left $ \ prod \ limits_ {i = l} ^ {mid} (x + i) $ right is $ \ prod \ limits_ {i = mid + 1} ^ {r} (x + i ) $

If the same number of items found, the former is set $ F (x) $ that the latter is $ F (x + mid-l + 1) $. Provided $ u = mid-l + 1, F (x) = \ sum \ limits_ {t = 0} ^ {c} a_t x ^ t $.

You can then find a bit like the binomial theorem, a technology of expression.

$F(x+u)=\sum\limits_{t=0}^{c} a_t (x+u)^t$.

$=\sum\limits_{t=0}^{c} a_t \sum\limits_{i=0}^{t} \binom{t}{i} x^i u^{t-i}$.

$=\sum\limits_{i=0}^{c} i! x^i \sum\limits_{t=i}^{c} \frac{u^{t-i}}{(t-i)!} t! $

Convolution obvious form. After the recursive solution $ F (x) $, do it again as long as the convolution coefficients can be obtained on the other side.

In particular, if a number is odd, so much out of a violent ride up just fine.

Time complexity $ T (n) = T (\ frac {n} {2}) + O (2n \ log \ n) = O (n \ log \ n) $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define mod 998244353
 4 #define S (1<<22)
 5 int n,m,len=1,rev[S],r[S],ans[S],t[S],fac[S],inv[S],R[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=0){
 9     for(int i=0;i<len;++i)if(rev[i]>i)swap(a[rev[i]],a[i]);
10     for(int i=1;i<len;i<<=1)for(int j=0,w=qp(3,(mod-1)/2/i*(op?-1:1)+mod-1);j<len;j+=i<<1)for(int k=j,x,y,t=1;k<j+i;++k,t=1ll*t*w%mod)
11         x=a[k],y=1ll*a[k+i]*t%mod,a[k]=mo(x+y),a[k+i]=mo(x-y+mod);
12     if(op)for(int iv=qp(len,mod-2),i=0;i<len;++i)a[i]=1ll*a[i]*iv%mod;
13 }
14 void solve(int l,int r){
15     if(l==r){ans[1]=1;ans[0]=2;return;}
16     int md=l+r>>1,Len=r-l+1;if(Len&1)md--;
17     solve(l,md);
18     len=1;while(len<=Len)len<<=1;
19     for(int i=0;i<len;++i)rev[i]=rev[i>>1]>>1|(i&1?len>>1:0);
20     int L=md-l+1;t[0]=1;
21     for(int i=1;i<=L;++i)t[i]=1ll*t[i-1]*L%mod;
22     for(int i=0;i<=L;++i)t[i]=1ll*t[i]*inv[i]%mod,R[i]=ans[i]*1ll*fac[i]%mod;
23     for(int i=L+1;i<len;++i)t[i]=R[i]=0;
24     reverse(t,t+L+2);
25     NTT(R);NTT(t);
26     for(int i=0;i<len;++i)t[i]=1ll*t[i]*R[i]%mod;
27     NTT(t,-1);
28     for(int i=0;i<=L;++i)t[i]=1ll*t[i+L+1]*inv[i]%mod;
29     for(int i=L+1;i<len;++i)t[i]=0;
30     NTT(t);NTT(ans);
31     for(int i=0;i<len;++i)ans[i]=1ll*ans[i]*t[i]%mod;
32     NTT(ans,-1);
33     if(Len&1){t[0]=0;
34         for(int i=0;i<Len;++i)t[i+1]=ans[i],t[i]=(t[i]+1ll*ans[i]*r)%mod;
35         for(int i=0;i<=Len;++i)ans[i]=t[i];
36     }
37 }               
38 int main(){
39     cin>>n>>m;fac[0]=1;
40     for(int i=1;i<S;++i)fac[i]=1ll*fac[i-1]*i%mod;
41     inv[S-1]=qp(fac[S-1],mod-2);
42     for(int i=S-2;~i;--i)inv[i]=inv[i+1]*(i+1ll)%mod;
43     solve(2,n);
44     int tot=0;
45     for(int k=1;k<=m&&k<=n;++k)tot=(tot+1ll*ans[n-k]*fac[m-1]%mod*inv[k-1]%mod*inv[m-k])%mod;
46     cout<<tot<<endl;
47 }
View Code

 

T2: Fenwick tree

Effect: $ k $ hex Fenwick tree, written in the wrong $ x + = lowbit (x) $ single point increase. (E.g., when $ k = 3 $ $ lowbit (15) = 6 $ and Fenwick tree should be added to the normal $ 3 $). Seeking the incorrect output. $ N \ le 10 ^ 9, m, k \ le 2 \ times 10 ^ 5 $

Found an error adder value will $ lowbit $ ring. All points to $ X $ $ x + lowbit (x) $ connected edge, the shape will be a tree.

If the least bit of rank (not the value) remains unchanged, we call this side is the heavy side.

If you only consider the weight side, the last several chain is constructed, the first chain or point of another chain, or n-point greater than $ $ position.

We use data structures for heavy maintenance, you can rest rampage.

The heavy chain is the suffix maintenance operation, a single enumeration. It may be converted to a single point addition, the prefix search. Such constant is smaller, no longer need to mark what lazy.

Several dynamic segment tree to resolve a prescription. Subscripts are $ [1, n] $ to.

Now the question is given one point, the chain needs to quickly find it first in order to find the root of the corresponding segment of the tree.

Consider doubled. Provided $ st [i] [j] $ $ lowbit $ represents a value of $ i $, the subtractor borrow $ 2 $ J ^ correspond to the few. That is, $ x = x + lowbit (x) $ reverse operation.

Example Sub: number in hexadecimal $ $ $ 10 $ 127. Which is $ lowbit $ $ $ 7, can borrow $ \ frac {127} {10} = 12 $ times, that is, $ st [3] [st [2] [7]] $. Where $ 12 = 2 ^ 2 ^ 3 + 2 $

If the number of roots is looking for an integral multiple of decimal, hexadecimal then extracted like a single operator. That $ 12,700 $ find is $ 100st [3] [st [2] [7]] $

For points not on the chain (i.e., pointing to the first chain strand is not greater than n positions), so there is no chain into the circulation, it can be a long chain is $ O (log) $ level

In other words, such points as compared to $ k $ is really just is not enough number of $ 2 $, the number of $ 2 $ enough current position will become $ 0 $ to enter the other chain

It is determined whether a point based on chain is: the number of comparisons of its $ lowbit $ and $ k $ of $ 2 $ who many, if $ k $ more it shows not on the chain, violent jump, or find now get the tree line on the line.

So the total number of rampaging is $ log_k n \ log_2 k $. Actually not much.

Maintain the original value of the individual to open a $ map $ like enough.

Seeking $ lowbit $ complexity is $ O (log) $ of

Because more frequently jump when $ k = 2 $, constant getting bigger, this time with a $ lowbit $-bit arithmetic is better, otherwise the card may be often.

The time complexity is about $ O (m \ log \ n \ + \ m \ log_2 k \ log_k \ n) $

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define S 53333333
 4 #define s 3333333
 5 unordered_map<int,int>M,rt;
 6 int lc[S],w[S],rc[S],pc,lcnt,n,p,k,m,iv[29][s],rm[s],crm[s];
 7 int lowbit(int x){if(k==2)return x&-x;int r=1;while(x%k==0)x/=k,r*=k;return x%k*r;}
 8 int low(int x){if(k==2)return 1;while(x%k==0)x/=k;return x%k;}
 9 void add(int&p,int pos,int v,int cl=1,int cr=n){
10     if(!p)p=++pc;
11     if(cl==cr)return void(w[p]^=v);
12     if(pos<=cl+cr>>1)add(lc[p],pos,v,cl,cl+cr>>1);
13     else add(rc[p],pos,v,(cl+cr>>1)+1,cr);
14     w[p]=w[lc[p]]^w[rc[p]];
15 }
16 int ask(int p,int r,int cl=1,int cr=n){
17     if(!p)return 0;
18     if(cr<=r)return w[p];
19     return ask(lc[p],r,cl,cl+cr>>1)^(r>cl+cr>>1?ask(rc[p],r,(cl+cr>>1)+1,cr):0);
20 }
21 int find(int x){
22     int r=rm[low(x)],t=x,c=0;while(t%k==0)t/=k,c++;t/=k;
23     for(int i=28;~i;--i)if(t&1<<i)r=iv[i][r];
24     while(c--)r*=k;return r;
25 }
26 int main(){
27     cin>>n>>m>>k;n++;
28     int _=k;while(!(_&1))p++,_>>=1;
29     for(int i=1;i<k;++i)rm[i]=i&1?i:rm[i>>1],crm[i]=i&1?0:crm[i>>1]+1;
30     for(int i=1;i<k;++i)iv[0][i]=rm[rm[i]+_>>1];
31     for(int i=1;i<29;++i)for(int j=1;j<k;++j)iv[i][j]=iv[i-1][iv[i-1][j]];
32     for(int $=0,op,x,y;$<m;++$){
33         scanf("%d%d",&op,&x);
34         if(op^1){
35             int ans=0;
36             while(x)ans^=crm[low(x)]<p?M[x]:ask(rt[find(x)],x),x-=lowbit(x);
37             printf("%d\n",ans);
38 
39         }else{
40             scanf("%d",&y);
41             while(x<=n&&crm[low(x)]<p)M[x]^=y,x+=lowbit(x);
42             if(k^2)add(rt[find(x)],x,y);
43         }
44     }
45 }
View Code

 

T3: Gifts

Effect: $ n $ long ring selected location $ m $, $ k $ not continuous over adjacent selected. Isomorphic cycle, the number of program? $ T \ le 5, l \ le m \ le n \ le 10 ^ 6 $

Cycling also can not think of a homogeneous group theory, I am probably a fool.

$ Burnside $ directly sets. Enumeration (group theory) of the length of the loop, is seeking $ \ sum \ limits_ {i | gcd (n, m)} \ varphi (i) F (\ frac {n} {i}, \ frac {m} {i}) $

$ F (n, m) $ represents a ring selected from the $ m $ n $ $ point adjacent program number does not exceed $ k $ th cycle of a different configuration.

Consider how demand. End to end $ k $ does not exceed this limit quite disgusting, so we have to let this thing fixed Chin restrictions were lifted.

We handpicked the first position certainly is not selected, then the rest is a matter of sequence.

Several enumeration over $ k $ th segment repellent capacity, interposer method calculation scheme.

Time complexity $ O (n \ log \ n) $ of.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define mod 998244353
 4 #define S 1111111
 5 int n,m,k,t,g,ans,fac[S],inv[S];
 6 int gcd(int a,int b){return b?gcd(b,a%b):a;}
 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 int phi(int x){
 9     int a=x;
10     for(int i=2;i*i<=x;++i)if(x%i==0){
11         a=a/i*(i-1);
12         while(x%i==0)x/=i;
13     }if(x^1)a=a/x*(x-1);return a;
14 }
15 int C(int b,int t){return b<t||t<0?0:1ll*fac[b]*inv[t]%mod*inv[b-t]%mod;}
16 int cal(int n,int m){n-=m;int a=0;for(int t=0;t*k<=m&&t<=n;++t)a=(a+(t&1?mod-1ll:1ll)*C(m-t*k+n-1,n-1)%mod*C(n,t))%mod;return 1ll*a*(n+m)%mod*qp(n,mod-2)%mod;}
17 int main(){
18     fac[0]=1;for(int i=1;i<S;++i)fac[i]=1ll*fac[i-1]*i%mod;
19     inv[S-1]=qp(fac[S-1],mod-2);
20     for(int i=S-2;~i;--i)inv[i]=inv[i+1]*(i+1ll)%mod;
21     cin>>t;while(t--){cin>>n>>m>>k;g=gcd(n,m);ans=0;k++;
22         for(int d=1;d*d<=g;++d)if(g%d==0){
23             ans=(ans+1ll*phi(d)*cal(n/d,m/d))%mod;
24             if(d*d^g)ans=(ans+1ll*phi(g/d)*cal(n*d/g,m*d/g))%mod;
25         }cout<<1ll*ans*qp(n,mod-2)%mod<<endl;
26     }
27 }
View Code

 

Guess you like

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