Advertisement
Plabon_dutta

C. Counting Orders

May 15th, 2023
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int Mod = 1e9 + 7;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  9.  
  10.     int testcase;
  11.     cin >> testcase;
  12.     while(testcase--) {
  13.         int n;
  14.         cin >> n;
  15.  
  16.         vector <int> a, b;
  17.         for (int i = 0; i < n; i++) {
  18.             int x;
  19.             cin >> x;
  20.             a.push_back(x);
  21.         }
  22.  
  23.         for (int i = 0; i < n; i++) {
  24.             int x;
  25.             cin >> x;
  26.             b.push_back(x);
  27.         }
  28.  
  29.         sort(a.begin(), a.end());
  30.         sort(b.rbegin(), b.rend());
  31.  
  32.         long long int ans = 1;
  33.         for (int i = 0; i < n; i++) {
  34.             int it = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
  35.             if (it == n) ans *= 0;
  36.             ans *= (n - it - i);
  37.             ans %= Mod;
  38.         }
  39.  
  40.         cout << ans << '\n';
  41.     }  
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement