Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define dprint(v) cerr << #v"=" << v << endl //;)
  4. #define forr(i,a,b) for(int i=(a); i<(b); i++)
  5. #define forn(i,n) forr(i,0,n)
  6. #define dforn(i,n) for(int i=n-1; i>=0; i--)
  7. #define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
  8. #define sz(c) ((int)c.size())
  9. #define zero(v) memset(v, 0, sizeof(v))
  10. #define pb push_back
  11. #define fst first
  12. #define snd second
  13. typedef long long ll;
  14. typedef pair<int,int> ii;
  15.  
  16. const int MAXN=100100;
  17. const ll MOD=1e9+7;
  18. int n, p[MAXN], v[MAXN];
  19.  
  20. int main() {
  21.     ios::sync_with_stdio(0);
  22.     while(cin >> n){
  23.         forn(i,n) cin >> p[i];
  24.         sort(p,p+n);
  25.         zero(v);
  26.         forn(_,n) { int c; cin >> c;
  27.             int idx = upper_bound(p,p+n,c)-p;
  28.             if (idx) v[idx-1]++;
  29.         }
  30.         int av = 0;
  31.         ll p = 1;
  32.         dforn(i,n) {
  33.             av += v[i];
  34.             p = (p*av) % MOD;
  35.             av--;
  36.         }
  37.         cout << p << endl;
  38.     }
  39.     return 0;
  40. }
Advertisement
RAW Paste Data Copied
Advertisement