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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <bits/stdc++.h> using namespace std; #define int long long #define resetIO(x) \ freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout) #define debug(fmt, ...) \ fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) template <class _Tp> inline _Tp& read(_Tp &x) { bool sign = false; char ch = getchar(); long double tmp = 1; for (; !isdigit(ch); ch = getchar()) sign |= (ch == '-'); for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48); if (ch == '.') for (ch = getchar(); isdigit(ch); ch = getchar()) tmp /= 10.0, x += tmp * (ch ^ 48); return sign ? (x = -x) : x; } template <class _Tp> inline void write(_Tp x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar((x % 10) ^ 48); } const int MAXN = 6e3 + 10; const int INFL = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; struct node { int x, op; bool operator<(const node &o) const { return x == o.x ? op < o.op : x < o.x; } }; int n, m, s[MAXN], t[MAXN], dp[2][MAXN][2]; node a[MAXN]; void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } signed main() { read(n); for (int i = 1; i <= n; ++i) read(s[i]), a[++m] = {s[i], 0}; for (int i = 1; i <= n; ++i) read(t[i]), a[++m] = {t[i], 1}; sort(a + 1, a + m + 1); int u = 0; dp[u ^ 1][0][1] = 1; for (int i = 1; i <= m; ++i, u ^= 1) { memset(dp[u], 0, sizeof(dp[u])); for (int j = 0; j <= n; ++j) { if (a[i].op == 0) { add(dp[u][j][0], dp[u ^ 1][j][0]); add(dp[u][j][0], dp[u ^ 1][j][1]); if (j) { add(dp[u][j][0], dp[u ^ 1][j - 1][0]); add(dp[u][j][1], dp[u ^ 1][j - 1][1]); } } else { add(dp[u][j][0], dp[u ^ 1][j + 1][0] * (j + 1) % MOD); add(dp[u][j][1], dp[u ^ 1][j + 1][1] * (j + 1) % MOD); add(dp[u][j][1], dp[u ^ 1][j][1]); } } } int sum = 0; add(sum, dp[u ^ 1][0][0]); add(sum, dp[u ^ 1][0][1]); write(sum), putchar('\n'); return 0; }
|