Identify the Operations
阿新 • • 發佈:2020-11-12
連結 : http://codeforces.com/problemset/problem/1442/B
參考於 : https://blog.csdn.net/qq_43627087/article/details/109478770
列舉輪次
程式碼
#include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) inline int lowbit(int x) { return x & (-x); } #define ll long long #define pb push_back #define PII pair<int, int> #define fi first #define se second #define inf 0x3f3f3f3f const int N = 2e5 + 7; const int p = 998244353; int a[N], b[N]; int pos[N], id[N]; int main() { IO; int _; cin >> _; while (_--) { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> a[i]; pos[a[i]] = i; id[i] = 0; } for (int i = 1; i <= m; ++i) { cin >> b[i]; id[pos[b[i]]] = i; } id[0] = id[n + 1] = n + 7; ll ans = 1; for (int i = 1; i <= m; ++i) { int t = 0, idx = pos[b[i]]; if (id[idx - 1] < id[idx]) t++; if (id[idx + 1] < id[idx]) t++; ans = ans * t % p; } cout << ans << endl; } return 0; }