https://ac.nowcoder.com/acm/contest/3007/D
Although the obtained solution to a problem with the same conclusion, but still more than problem solution thinking trouble. .
10 questions over Question 8, 6 questions do trouble
Vomiting blood. . .
The A and B are sorted in ascending
A number of position then each is able to fill a range, the range to the last position is the right end, left end point does not fall
My idea is from a large number of small to fill, so that each can fill the position will not increase
A one bit for each selected to cover all of B in their own section in
F_n [i] represents the n bits, and now to the i-th
Because we can put the number of the i-th bit will be able to put the first bit i + 1, the i + 1 corresponding to the first consider bit away when the i-th bit into a
f_n [i] = f_n-1 [i + 1] * L [i], L [i] denotes the i-th bit interval coverage is much
f_n-1[i+1]=f_n-2[i+2]*(L[i+1]-1)
f_n-2[i+2]=f_n-3[i+3]*(L[i+2]-2)
……
f_n[1]=L[1]*(L[2]-1)*(L[3]-2)*(L[4]-3)*(L[5]-4)*(L[n]-(n-1))
Problem solutions from small to large to fill
Because the smaller that position need to have a certain number of fill
The i-th position can be placed into the first must be able to position i + 1
Therefore, the program number = L [. 1] * (L [2] -1) * (L [. 3] -2) * (L [. 4] -3) * (L [. 5] -4) * (L [n-] - (n-1))
#include<cstdio> #include<algorithm> using namespace std; #define N 100001 const int mod=1e9+7; int a[N],b[N]; int L[N]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); for(int i=1;i<=n;++i) scanf("%d",&b[i]); sort(b+1,b+n+1); sort(a+1,a+n+1); int m=n; for(int i=n;i;--i) { while(m && a[i]<=b[m]) m--; L[m+1]++; if(i<=m) { printf("0"); return 0; } } for(int i=2;i<=n;++i) L[i]+=L[i-1]; int ans=1; for(int i=1;i<n;++i) ans=1ll*ans*(L[i]-i+1)%mod; printf("%d",ans); return 0; }