原题链接:
题解:
采用暴力只拿了35分。
满分题解参考Pujx大佬的博客:
CCF-CSP认证考试 202312-4 宝藏 100分题解_csp宝藏-CSDN博客
代码:
35分暴力代码:
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5 + 10;
int n, m;
int v[N][2][2];
int tag[N];//
int mod = 998244353;
deque<LL> q;
LL ans[2][2];
deque<int> sta;//模拟栈,用于存储上一次是从前还是从后插入
void process(int cur) {
if (tag[cur] == 1) {
q.push_front(cur);
sta.push_back(1);
}
else if (tag[cur] == 2) {
q.push_back(cur);
sta.push_back(0);
}
else {
if (!q.empty()) {
if (sta.back()) q.pop_front();
else q.pop_back();
sta.pop_back();
}
}
}
int main() {
cin >> n >> m;
for (int i = 1;i <= n;i++) {
cin >> tag[i];
if (tag[i] == 1 || tag[i] == 2) {
cin >> v[i][0][0] >> v[i][0][1] >> v[i][1][0] >> v[i][1][1];
}
}
for (int i = 1;i <= m;i++) {
int p;cin >> p;
if (p == 1) {
int k, t;cin >> k >> t;
if (t == 1 || t == 2) {
cin >> v[k][0][0] >> v[k][0][1] >> v[k][1][0] >> v[k][1][1];
}
tag[k] = t;
}
else {
q.clear();
sta.clear();
memset(ans, 0, sizeof(ans));
int l, r;cin >> l >> r;
for (int i = l;i <= r;i++) {
process(i);
}
if (q.size() == 0) {
cout << 1 << " " << 0 << " " << 0 << " " << 1 << endl;
}
else if (q.size() == 1) {
cout << v[q.front()][0][0] << " " << v[q.front()][0][1] << " " << v[q.front()][1][0] << " " << v[q.front()][1][1] << endl;
}
else {
for (int i = 0;i < 2;i++)
for (int j = 0;j < 2;j++)
ans[i][j] = v[q.front()][i][j];
q.pop_front();
while (!q.empty()) {
LL tmp[2][2];
memset(tmp, 0, sizeof(tmp));
for (int i = 0;i < 2;i++)
for (int j = 0;j < 2;j++) {
tmp[i][j] = (1ll * ans[i][0] * v[q.front()][0][j] + 1ll * ans[i][1] * v[q.front()][1][j]) % mod;
}
q.pop_front();
for (int i = 0;i < 2;i++)
for (int j = 0;j < 2;j++)
ans[i][j] = tmp[i][j];
}
cout << ans[0][0] << " " << ans[0][1] << " " << ans[1][0] << " " << ans[1][1] << endl;
}
}
}
}
坑点:
注意队列为空的时候,密码为单位矩阵,而非全零矩阵。