BZOJ4569: [Scoi2016] Meng Meng da

Source: Internet
Author: User

Description A large number of length n, with S1s2s3 ... SN, wherein SI represents the number of the first bit, S1 is the number of the highest bit, tells you some restrictions, each condition is expressed as four number, L1,R1,L2,R2, that is, two length of the same interval, indicating the substring SL1SL1+1SL1+2...SR1 and sl2sl2+1sl2+2 ... Sr2 exactly the same. For example, when n=6, a restrictive condition l1=1,r1=3,l2=4,r2=6, then 123123,351351 meet the conditions, but 12012,131141 do not meet the conditions, the former number of the length is not 6, the latter second and the fifth place is different. Ask how many of the above conditions are met. Input two numbers n and m for the first row, respectively, for the length of the large number, and the number of constraints. Next m, for line I, there are 4 number LI1,RI1,LI2,RI2, which represent the two intervals corresponding to the restriction condition. 1≤n≤10^5,1≤m≤10^5,1≤li1,ri1,li2,ri2≤n, and ensure ri1-li1=ri2-li2. Output

A number that represents the number of large numbers with a length of n that satisfies all conditions, and the answer can be large, so the result of the output answer modulo 10^9+7.

Sample Input1 2 3 4
3 3 3 3Sample Output -I am convinced of the ingenious idea. It is not difficult to find that each operation is equivalent to merging the connected components sequentially in two intervals, if the violent merger is clearly O (NM). What do we do? We set up the St table for the sequence so that we can understand it as a nlogn point, merging chunks first, then recursively merging small chunks. Note that each point participates in only one merge, and the total time complexity is still O (Mlogn). don't know why it's faster to merge by rank instead.
#include <cstdio> #include <cctype> #include <queue> #include <cstring> #include <algorithm > #define REP (i,s,t) for (int. i=s;i<=t;i++) #define DWN (I,S,T) for (int. i=s;i>=t;i--) #define REN for (int i=first[x ];i;i=next[i]) using namespace Std;const int Buffersize=1<<16;char Buffer[buffersize],*head,*tail;inline Char Getchar () {if (head==tail) {int l=fread (Buffer,1,buffersize,stdin); tail= (Head=buffer) +l;} return *head++;}    inline int read () {int X=0,f=1;char c=getchar (); for (;!    IsDigit (c); C=getchar ()) if (c== '-') f=-1;    for (; IsDigit (c); C=getchar ()) x=x*10+c-' 0 '; return x*f;} typedef long LONG Ll;const int maxn=100010;int n,m,a[maxn],pa[maxn*20],s[maxn*20],log[maxn];int ID (int k,int x) {return k *n+x;} int findset (int x) {return pa[x]==x?x:findset (pa[x]);} void merge (int x,int y,int k) {int f1=findset (ID (k,x)), F2=findset (ID (k,y)), if (F1!=F2) {if (S[f1]>s[f2]) swap (F1,F2); Pa[f1]=f2;if (S[f1]==s[f2]) s[f2]++;if (k) Merge (x,y,k-1), merge (x+ (1<<k-1), y+ (1<< k-1), k-1);}} int main () {n=read (); M=read (); for (int i=0; (1<<i) <=n;i++) Rep (j,1,n) pa[id (i,j)]=id (i,j), S[id (i,j)]=1; Log[0]=-1;rep (i,1,n) log[i]=log[i>>1]+1;rep (i,1,m) {int a=read (), B=read (), C=read (), D=read (), k=Log[b-a+1]; Merge (a,c,k); Merge (b-(1<<k) +1,d-(1<<k) +1,k);} int Cnt=0;rep (I,1,N) a[i]=findset (ID (0,i)), sort (a+1,a+n+1), Rep (i,1,n) if (A[i]!=a[i-1]) cnt++;if (cnt==1) puts ("10"); else {ll ans=9;rep (i,1,cnt-1) (ans*=10)%=1000000007;printf ("%lld\n", ans);} return 0;}

  

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.