-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
49 lines (47 loc) · 1.07 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005],b[200005],M=1000000007;
int main()
{
fastio;
long long t,n,i,ans,cnt;
cin>>t;
while(t--)
{
ans=1;
cin>>n;
for(i=0;i<n;i++)
cin>>ara[i];
for(i=0;i<n;i++)
cin>>b[i];
vector<long long> vect;
for(i=0;i<n;i++)
vect.push_back(ara[i]);
sort(vect.begin(),vect.end());
sort(b,b+n,greater<long long>());
vector<long long>::iterator it;
for(i=0;i<n;i++)
{
it=upper_bound(vect.begin(),vect.end(),b[i]);
if(it!=vect.end())
{
cnt=n-(it-vect.begin())-i;
if(cnt<1)
{
ans=0;
break;
}
ans=(ans*cnt)%M;
}
else
{
ans=0;
break;
}
}
cout<<ans<<"\n";
}
return 0;
}