当前位置:网站首页>2022杭电多校第三场
2022杭电多校第三场
2022-07-29 13:55:00 【fslse】
f[i][0]表示序列S前i个元素已完成匹配且第i个元素来自序列P的方案数
f[i][1]表示序列S前i个元素已完成匹配且第i个元素来自序列Q的方案数
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0)
#define endl '\n'
typedef long long ll;
const ll mod = 998244353;
const int N = 2e6 + 10;
int n;
int a[N], b[N], c[N], cnt[N], pos[N][2];
ll f[N][2];
void solve(){
cin >> n;
for (int i = 1;i <= n;++i)cin >> a[i], pos[a[i]][0] = i;
for (int i = 1;i <= n;++i)cin >> b[i], pos[b[i]][1] = i;
memset(cnt + 1, 0, n * 4);
for (int i = 1;i <= n * 2;++i)cin >> c[i], ++cnt[c[i]];
if (*max_element(cnt + 1, cnt + 1 + n) > 2){
cout << 0 << endl;
return;
}
for (int i = 1;i <= n * 2;++i)
f[i][0] = f[i][1] = 0;
f[1][!(a[1] == c[1])] = 1, f[1][b[1] == c[1]] = 1;
for (int i = 2, j;i <= n * 2;++i){
if (pos[c[i - 1]][0] + 1 == pos[c[i]][0])f[i][0] = (f[i][0] + f[i - 1][0]) % mod;
if (pos[c[i - 1]][1] + 1 == pos[c[i]][1])f[i][1] = (f[i][1] + f[i - 1][1]) % mod;
j = i - pos[c[i - 1]][0];
if (b[j] == c[i])f[i][1] = (f[i][1] + f[i - 1][0]) % mod;
j = i - pos[c[i - 1]][1];
if (a[j] == c[i])f[i][0] = (f[i][0] + f[i - 1][1]) % mod;
}
cout << (f[n * 2][0] + f[n * 2][1]) % mod << endl;
}
int main(){
IOS;
int T;
cin >> T;
while (T--){
solve();
}
return 0;
}
边栏推荐
- 无线传感器网络定位综述
- What is the difference between the legendary server GOM engine and the GEE engine?
- Understand the yolov7 network structure
- 简单了解单例模式
- app小程序开发的营销优势有什么?
- 一文搞懂JS的原型链
- 开放式耳机推荐哪款最好最实用、最好的开放式耳机推荐
- EA&UML日拱一卒-活动图::Feature和StuctualFeature
- 解决:Parameter 0 of method ribbonServerList in com.alibaba.cloud.nacos.ribbon.NacosRibbonClientConfigu
- 国内helm快速安装和添加常用charts仓库
猜你喜欢
随机推荐
gdb调试常用概念整理
1191. 家谱树
你真的会用Console.log吗?
app小程序开发的营销优势有什么?
尚硅谷大叔培训:揭秘Flink四种执行图——ExecutionGraph和物理执行图
关于知识付费的一些思考
PAT serie a A1021 Deepest Root
开关电源-半桥LLC控制
human pose estimation-DEKR2021CVPR
The new technical director, who is in the form of a isXxx Boolean type definition, tomorrow need not come!
EA&UML日拱一卒-活动图::StartClassifierBehavior和StartObjectBehavior
EA&UML日拱一卒-活动图::Object actions(续)
leetcode链表专题
力扣 206.反转链表--递归解决
Vscode搭建ESP32-C3开发环境
【Postman】下载与安装(新手图文教程)
国产手机将用户变成它们的广告肉鸡,难怪消费者都买iPhone了
还在开发短信验证码登录?试试(本机号码一键登录)
How to Improve Embedded Programming with MISRA
马尔可夫跳变线性系统最优控制的研究现状与进展









