[bzoj4569] [SCOI2016] Meng Meng da

Source: Internet
Author: User

Main topic

There is an n-digit number with no leading 0, and there are m-constrained shapes such as [L1,R1]=[L2,R2], which ask the number of satisfying conditions, the answer modulo 10^9+7.

Double

We use ST table, f[i,j] to denote [i,i+2^j-1] this paragraph.
Then each paragraph is initially made into a single set.
For a limit, you can split the log copies and then merge the collections.
Then, if any f[s,t] and f[i,j] belong to the same set, then F[s,t-1] and f[i,j-1] and f[s+2^ (t-1) -1,t-1] and f[i+2^ (j-1) -1,j-1] should all belong to the same collection.
In order to meet this limit, as long as the last layer to do, the next layer of the merger can be.
Attention must be put into the number of large numbers in the number of small.
The statistical answer is very simple, the specific look at the code.

#include <cstdio>#include <algorithm>#define FO (i,a,b) for (i=a;i<=b;i++)#define FD (I,A,B) for (i=a;i>=b;i--)using namespace Std;typedef Long LongllConst intmaxn=100000+Ten, mo=1000000007, maxd= -;intfa[maxn* +],ID[MAXN] [ +],di[maxn* +][2],two[ +];intI,j,k,l1,r1,l2,r2,s,t,n,m,ans,tot;intGETFA (intx) {returnFA[X]?FA[X]=GETFA (Fa[x]): x;}intMergeintXintY) {X=GETFA (x); Y=GETFA (y);if(x>y) Swap (x, y);if(x!=y) fa[y]=x;}intMain () {two[0]=1; Fo (i,1, Maxd) two[i]=two[i-1]*2; scanf"%d%d", &n,&m);if(n==1) {printf ("10\n");return 0; } FO (i,1, N) Fo (J,0, Maxd)IDI [j]=++tot,di[tot][0]=i,di[tot][1]=j; Fo (i,1, m) {scanf ("%d%d%d%d", &AMP;L1,&AMP;R1,&AMP;L2,&AMP;R2); FD (J,maxd,0)if(l1+two[j]-1&LT;=R1) {Merge (ID[L1] [j],ID[L2]                [j]);            L1+=TWO[J];L2+=TWO[J]; }} FD (J,maxd,1) Fo (i,1, n) {K=GETFA (IDI            [j]); s=di[k][0];t=di[k][1]; MergeID[S] [t1],IDI [J-1]); MergeID[s+two[t-1]][t-1],ID[i+two[j-1]][j-1]); } ans=1; Fo (i,1, N)if(!fa[IDI [0]]) ans= (LL) ans* (i==1)?9:Ten)%mo; printf"%d\n", ans);}

[bzoj4569] [SCOI2016] Meng Meng da

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.