BZOJ2751[HAOI2012] Easy Title
Test instructions
It is known that a sequence a for all A[i] is a natural number of 1~n, and some a[i] cannot take some values to find out the product of all possible sequences and the value of MoD 1000000007.
Exercises
The n≤109 in question is actually 109 ... First, the equation S[l,r]=s[l,k]*s[k+1,r] (S[l,r] represents the sum of the possible values of the a[i] of all l≤i≤r of the L to R) and therefore S[1,n] is equal to that of all A[i]. So we first find the a[i of 1 to N, and each constraint is sorted by I, and the number that cannot be taken in this and the subtract constraint is the same as the value of all possible values. Multiply these a[i], and the rest of the unrestricted a[i] is solved with a quick power.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #definell Long Long5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMoD 10000000077 using namespacestd;8 9 structnd{Ten ll A, B; One BOOL operator< (Constnd &c)Const{ A if(A!=C.A)returna<c.a;Else returnb<c.b; - } - }; the ll Power (ll A,ll b) { - if(b==0)return 1;if(b==1)returnA ll C=power (a,b>>1)%MoD; - if(b&1)returnC*c%mod*a%mod;Else returnc*c%MoD; - } +nd ns[200000]; - intMain () { +ll n,m,a1=0, A2,A3,A4; ll K; scanf"%lld%lld%lld",&n,&m,&k); AInc (I,1, k) scanf ("%lld%lld", &ns[i].a,&ns[i].b); Sort (ns+1, ns+k+1); atInc (I,1Kif(i==1|| ns[i].a!=ns[i-1].A) a1++; a2=n* (n+1)/2%mod; a3=a4=1; -Inc (I,1Kif(i==1|| ns[i].a!=ns[i-1].A) a4=a4*a3%mod,a3=a2,a3= (a3-ns[i].b) >=0? (a3-ns[i].b)%mod: (a3-ns[i].b) +MoD; - Else if(ns[i].b!=ns[i-1].B) a3= (a3-ns[i].b) >=0? (a3-ns[i].b)%mod: (a3-ns[i].b) +MoD; -A4=a4*a3%mod; A4=a4*power (A2,M-A1)%mod; printf"%lld", A4); -}
20160419
BZOJ2751[HAOI2012] Easy Title