Identify the Operations

链接 : 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;
}

posted @ 2020-11-07 15:44  phr2000  阅读(80)  评论(0编辑  收藏  举报