首页 > 其他 > 详细

Identify the Operations

时间:2020-11-07 19:50:22      阅读:33      评论:0      收藏:0      [点我收藏+]

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

Identify the Operations

原文:https://www.cnblogs.com/phr2000/p/13941214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!