Codeforces 873div2 C
// compile: make data
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) _debug_print(#x, x);
#else
#define debug(x...) {};
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define INTMAX (int)(9223372036854775807)
#define INF (int)(1152921504606846976)
#define double long double
#define int long long
#define P 1000000007
#define MAXN 200010

int binary_search(vector<int> &a, int l, int r, int x) {
    int ans = -1;
    while (l <= r) {
        int mid = l + (r-l) / 2;
        if (a[mid] <= x) l = mid + 1;
        else ans = mid, r = mid - 1;
    }
    return ans;
}

void solve() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<int> c;
    for (int i = n-1; i >= 0; --i) {
        int id = binary_search(a, 0, n-1, b[i]);
        if (!~id) {
            cout << 0 << endl;
            return;
        }
        c.push_back(n - id);
    }
    int ans = 1;
    rep(i, 0, sz(c)) {
        if (c[i] - i <= 0) {
            cout << 0 << endl;
            return;
        }
        ans = ans * (c[i] - i) % P;
    }
    cout << ans << endl;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int _; cin >> _;
    while (_--) solve();

    return 0;
}

Comments

  1. 3 weeks ago
    2026-10-11 22:55:15

    [8882]toto80 Login – Trusted Online Slot and TNG Deposit Malaysia,Access toto80 login to enjoy trusted online slot Malaysia. Download the toto80 app APK for easy access and fast casino deposit via TNG. Join now! visit: toto80

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next