1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include <bits/stdc++.h> #define mp make_pair #define fst first #define snd second using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 998244353; const int N = 1000010; int n, m, type, ansx, ansy; int a[N], len;
inline int add(const int &x, const int &y) { return x + y < mod ? x + y : x + y - mod; } inline int sub(const int &x, const int &y) { return x - y < 0 ? x - y + mod : x - y; } inline int mul(const int &x, const int &y) { return (int)((ll)x * y % mod); }
struct mtrx { int a[2][2]; mtrx() { memset(a, 0, sizeof(a)); } inline mtrx operator*(const mtrx &yy)const { mtrx res = mtrx(); for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) for(int k = 0; k < 2; k++) res.a[i][j] = add(res.a[i][j], mul(a[i][k], yy.a[k][j])); return res; } }; mtrx sum[N], inv[N], ans;
void insert(int x) { ++len; mtrx mu; mu.a[1][0] = mu.a[0][1] = 1; mu.a[0][0] = x, sum[len] = sum[len - 1] * mu; mu.a[0][0] = 0, mu.a[1][1] = sub(0, x), inv[len] = mu * inv[len - 1]; } int main() { scanf("%d%d%d", &n, &m, &type); sum[0].a[0][0] = sum[0].a[1][1] = 1; inv[0].a[0][0] = inv[0].a[1][1] = 1; for(int i = 1, x; i <= n; i++) scanf("%d", &x), insert(x); for(int opt, x, y; m; --m) { scanf("%d", &opt); if(opt == 1) { scanf("%d", &x); if(type) x = x ^ ansx ^ ansy; insert(x); } else { scanf("%d%d", &x, &y); if(type) x = x ^ ansx ^ ansy, y = y ^ ansx ^ ansy; ans = inv[x - 1] * sum[y]; ansx = ans.a[0][0], ansy = ans.a[1][0]; printf("%d %d\n", ansx, ansy); } } return 0; }
|