Bzoj 4584: [Apio2016] Rowing

Source: Internet
Author: User

4584: [Apio2016] Rowing time limit:70 Sec Memory limit:256 MB
[Submit] [Status] [Discuss] Description in the Seoul city, the Han River traverses things. On the north bank of the Han River, a rowing school is scattered from west to east, numbered sequentially. Each school has several rowing boats. All the rowing boats in the same school have the same color, and the rowing colors of different schools differ. Rowing boats of the same color are considered to be the same. Each school can choose to send some rowing boats to participate in the festival celebrations, or choose not to send any rowing boats to participate. If the numbered schools choose to send rowing boats to participate in the celebrations, then the number of rowing boats sent can be arbitrarily selected between Ai and Bi (AI<=BI). It is worth noting that the school numbered I if choose to send a rowing boat to participate in the celebrations, then it sent the number of rowing boats must be larger than any one of the number of schools sent by the number of rowing. Enter the values of AI and bi for all schools, and find out how many possibilities are possible for a rowing boat, and must have at least one rowboat to attend the celebrations. The two cases are different if and only if there is a different number of rowing in a certain color of the celebration Input

The first line includes an integer n, which indicates the number of schools. The next n rows, each line consists of two positive integers, used to describe a school. Where the first line includes the

Two positive integers represent ai,bi (1<=ai<=bi<=10^9), N<=500output

The output line, an integer, representing all the possible number of plans to send a rowing boat divided by 1,000,000,007 to get the remainder

Sample Input2

1 2

2 3Sample Output7HINT Source

Topic links

See Dalao Blog to understand the link

1#include <bits/stdc++.h>2 3 using namespacestd;4 5 Const Long LongINF =1000000007;6 7 Const intMAXN =510;8 Long LongN, p, top, ans;9 Long LongINV[MAXN];Ten Long LongA[MAXN], B[MAXN], L[MAXN], R[MAXN]; One Long LongH[MAXN +MAXN]; A Long LongC[MAXN], G[MAXN]; -map<Long Long,int>K; -  theTemplate <typename tn>voidRead (TN &a) { -TN x =0, F =1;Charc =GetChar (); -      while(C <'0'|| C >'9') {if(c = ='-') F =-1; c =GetChar ();} -      while(c >='0'&& C <='9') {x = x *Ten+ C-'0'; c =GetChar ();} +A = f = =1? X:-x; - } +  A voidGet_inv () { atinv[1] =1; -      for(inti =2; I <= N; ++i) { -Inv[i] =-(inv[inf% i] * (inf/i))%INF; -          while(Inv[i] <0) Inv[i] + =INF; -     } - } in  - intMain () { to read (n); + GET_INV (); -      for(inti =1; I <= N; ++i) { the read (a[i]); * read (b[i]); $++B[i];Panax NotoginsengH[i + i-1] =A[i]; -H[i + i] =B[i]; the     } +Sort (H +1, H +1+ N +n); Atop = Unique (H +1, H + n + n +1)-H-1; the      for(inti =1; I <= top; ++i) { +K[h[i]] =i; -     } $      for(inti =1; I <= N; ++i) { $L[i] =K[a[i]]; -R[i] =K[b[i]]; -     } the //cout << top << "\ n"; - //for (int i = 1; I <= top; ++i) cout << h[i]<< "";Wuyi //for (int i = 1; I <= n; ++i) cout << l[i]<< "" <<r[i]<< "\ n"; theg[0] =1; -      for(intj =1; J <= Top; ++j) { Wu         intL = H[j +1] -H[j]; -c[0] =1; About //cerr<< "j =" <<j<< "\ n"; $          for(inti =1; I <= N; ++i) { -C[i] = c[i-1] * (L + i-1)% INF * Inv[i]%INF; - //cerr<<i<< "" <<C[i]<< "\ n"; -         } A          for(inti = n; i >0; --i) { +             if(L[i] <= J && R[i] >j) { the                 Long Longf =0, M =1, C =L; -                  for(intp = i-1; P >=0; --p) { $F = (f + c * g[p])%INF; the                     if(L[p] <= J && R[p] >= j +1) { thec = c[++m]; the                     } the                 } -G[i] = (G[i] + f)%INF; in             } the         } the     } About      for(inti =1; I <= N; ++i) ans = (ans + g[i])%INF; theprintf"%lld\n", ans); the     return 0; the}
View Code

Bzoj 4584: [Apio2016] Rowing

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.