当前位置:网站首页>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;
}
边栏推荐
- Children's programming electronics (graphical programming Scratch secondary level exam parsing (choice) in June 2022
- What is the difference between the legendary server GOM engine and the GEE engine?
- MLX90640 红外热成像仪测温传感器模块开发笔记(九)
- 【pytorch】1.6 tensor 基本运算
- 关于知识付费的一些思考
- 线程池工作流程-图示
- 【JS面试题】面试官问我:遍历一个数组用 for 和 forEach 哪个更快?
- 基于变胞机构的移动机器人构型设计研究综述
- leetcode链表专题
- human pose estimation-DEKR2021CVPR
猜你喜欢

Network connection optimization for instant messaging mobile terminal development

【论文阅读】异常检测的视频通过Self-Supervised和多任务学习

【JS高级】js之闭包对象_04

EA&UML日拱一卒-活动图::CallOperationAction(续)

推荐几款2022年好用的设备管理系统(软件)

还在开发短信验证码登录?试试(本机号码一键登录)

84.(cesium之家)cesium模型在地形上运动

有关包装类的一道经典面试题

Gee engine modification UI interface graphic tutorial

国内helm快速安装和添加常用charts仓库
随机推荐
trivy如何从非关系型数据库查询数据
无线传感器网络定位综述
深开鸿:万物智联的大江上,升起一轮开源鸿蒙月
【10点公开课】:快手GPU/FPGA/ASIC异构平台的应用探索
AI全流程开发难题破解之钥
【微信小程序】全局配置
The Location object of BOM series
基于降噪自编码器与改进卷积神经网络的采煤机健康状态识别
C#线程操作UI控件
Understand the yolov7 network structure
一文搞懂JS的原型链
手摸手写一个互联网黑话生成器
抓住这几个关键点,做薪酬数据分析并不难
iMedicalLIS监听程序(1)
1191. 家谱树
【pytorch】1.6 tensor 基本运算
验证二叉树的前序序列化[抽象前序遍历]
关于内部类
还在开发短信验证码登录?试试(本机号码一键登录)
【JS高级】js之闭包对象_04