#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 1e9 + 7; inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } //ruogu_alter const int N = 1e5 + 5; int n, a[N], pos[N], dat[N]; // void upd(int x, int y) { ++x; while (x < N) { dat[x] = max(dat[x], y); x += x & -x; } } int qry(int x) { ++x; int ans = -1; while (x) { ans = max(ans, dat[x]); x -= x & -x; } return ans; } int main() { n = getint(); rep(i, n) a[i] = getint() - 1; rep(i, n) pos[getint() - 1] = i; memset(dat, -1, sizeof(dat)); for (int i = n - 1; i >= 0; i--) { if (qry(pos[a[i]] - 1) > a[i]) return !printf("NO\n"); upd(pos[a[i]], a[i]); } printf("YES\n"); return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 998244353; inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } inline void add(int &x, int y) { x += y - mod; x += x >> 31 & mod; } //ruogu_alter const int M = 200 * 200 + 5; const int N = 205; int inv[M]; int n, m, f[3][N][N][N]; // void init() { inv[0] = inv[1] = 1; for (int i = 2; i < M; i++) { inv[i] = mul(mod - mod / i, inv[mod % i]); } } int main() { init(); n = getint(); m = getint(); rep(A, n - m + 1) { int i = A % 3, j = (A - 1 + 3) % 3, k = (A - 2 + 3) % 3; rep(B, n - m - A + 1) { rep(C, n - A - B + 1) { rep(D, n - A - B - C + 1) { f[i][B][C][D] = 0; if (A + B + C + D > 1) { ll ans = 0; if (A >= 2) ans += 1ll * A * (A - 1) / 2 * f[k][B + 2][C][D]; if (B >= 2) ans += 1ll * B * (B - 1) / 2 * f[i][B - 2][C][D]; if (C >= 2) ans += 1ll * C * (C - 1) / 2 * f[i][B][C - 2][D + 2]; if (D >= 2) ans += 1ll * D * (D - 1) / 2 * f[i][B][C][D - 2]; if (A >= 1 && B >= 1) ans += 1ll * A * B * f[j][B][C][D]; if (A >= 1 && C >= 1) ans += 1ll * A * C * f[j][B][C][D]; if (A >= 1 && D >= 1) ans += 1ll * A * D * f[j][B][C + 1][D - 1]; if (B >= 1 && C >= 1) ans += 1ll * B * C * f[i][B - 1][C - 1][D + 1]; if (B >= 1 && D >= 1) ans += 1ll * B * D * f[i][B - 1][C][D]; if (C >= 1 && D >= 1) ans += 1ll * C * D * f[i][B][C - 1][D]; ans %= mod; f[i][B][C][D] = mul(ans, inv[(A + B + C + D) * (A + B + C + D - 1) / 2]); add(f[i][B][C][D], 1); } } } } } cout << f[(n - m) % 3][0][m][0] << endl; return 0; }