第一次参加CSP,分数不是很高,但是考试之后还是想做一下考题练习一下,感觉第四题思路比第三题更直观一点,所以尝试了一下。题目如下:
题目中给出的测试样例,实测七个中前三个都可以通过,后四个由于样例过大过多,导致Windows Terminal会崩溃,所以无法完成测试。
代码中,操作使用map op来存储,第一个int表示操作的编号,第二个int表示每个操作中的操作码(1,2,3),matrix为输入的矩阵(当操作码为3时不需要输入矩阵)。当需要输出密码时,deque dq用来存储生成密码的矩阵,其中int用来表示存入dq的矩阵的次序先后,matrix表示当前矩阵。下面给出自己的代码(没有经过任何优化,完全顺着题目思路编写):
Python
#include
using namespace std;
using ll = long long;
const int MAX = 998244353;
class matrix
{
private:
array m;
public:
matrix();
matrix(const array &op);
matrix &operator=(matrix n);
matrix &operator=(const array &nm);
matrix &operator*=(const matrix &n); // 模998244353的乘法
matrix &operator%=(const int n);
void show();
};
int main(void)
{
int n, m;
map op;
deque dq;
cin >> n >> m;
for (int i = 1; i > oc;
if (oc == 3)
op.insert(make_pair(i, make_pair(oc, matrix(array({0, 0, 0, 0})))));
else
{
for (int j = 0; j > temp1[j];
matrix temp2(temp1);
op.insert(make_pair(i, make_pair(oc, temp2)));
}
}
for (int i = 1; i > choice;
if (choice == 1)
{
int loc, opcode;
cin >> loc >> opcode;
if (opcode == 3)
op[loc].first = opcode;
else
{
array temp;
for (int i = 0; i > temp[i];
op[loc] = make_pair(opcode, matrix(temp));
}
}
else if (choice == 2)
{
int l, r, cnt = 0;
matrix res({1, 0, 0, 1});
cin >> l >> r;
for (int i = l; i dq.back().first)
dq.pop_front();
else
dq.pop_back();
cnt--;
}
}
}
for (int i = 0; i