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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #include <iostream> #include <cstdio> using namespace std; const int p = 19260817; int n, m, arr[500010]; namespace smt { int tree[2][4000010], add[2][4000010], mul[2][4000010]; inline void pushup(int rt,int id) { tree[rt][id] = (tree[rt][id<<1] + tree[rt][id<<1|1]) % p; } inline void pushdown(int rt, int id, int l, int r) { int mid = l + r >> 1; tree[rt][id<<1] = ((long long)tree[rt][id<<1] * mul[rt][id] + (long long)add[rt][id] * (mid - l + 1) % p) % p; tree[rt][id<<1|1] = ((long long)tree[rt][id<<1|1] * mul[rt][id] + (long long)add[rt][id] * (r - mid) % p) % p; mul[rt][id<<1] = ((long long)mul[rt][id<<1] * mul[rt][id]) % p; mul[rt][id<<1|1] = ((long long)mul[rt][id<<1|1] * mul[rt][id]) % p; add[rt][id<<1] = ((long long)add[rt][id<<1] * mul[rt][id] + add[rt][id]) % p; add[rt][id<<1|1] = ((long long)add[rt][id<<1|1] * mul[rt][id] + add[rt][id]) % p; mul[rt][id] = 1, add[rt][id] = 0; } void build(int rt, int id, int l, int r) { mul[rt][id] = 1; if(l == r) { tree[rt][id] = arr[l] % p; return; } int mid = l + r >> 1; build(rt, id<<1, l, mid); build(rt, id<<1|1, mid + 1, r); pushup(rt, id); } void adjust1(int rt, int id, int x, int y, int k, int l, int r) { if(!id) return; if(x <= l && r <= y) { add[rt][id] = (long long)(add[rt][id] + k) % p; tree[rt][id] = (tree[rt][id] + (long long)(r - l + 1) * k) % p; return; } pushdown(rt, id, l, r); int mid = l + r >> 1; if(x <= mid) adjust1(rt, id<<1, x, y, k, l, mid); if(mid < y) adjust1(rt, id<<1|1, x, y, k, mid + 1, r); pushup(rt, id); } void adjust2(int rt, int id, int x, int y, int k, int l, int r) { if(!id) return; if(x <= l && r <= y) { tree[rt][id] = ((long long)tree[rt][id] * k) % p; mul[rt][id] = ((long long)mul[rt][id] * k) % p; add[rt][id] = ((long long)add[rt][id] * k) % p; return; } pushdown(rt, id, l, r); int mid = l + r >> 1; if(x <= mid) adjust2(rt, id<<1, x, y, k, l, mid); if(mid < y) adjust2(rt, id<<1|1, x, y, k, mid + 1, r); pushup(rt, id); } int query(int rt, int id, int x, int y, int l, int r) { if(!id) return 0; if(x <= l && r <= y) return tree[rt][id] % p; pushdown(rt, id, l, r); int mid = l + r >> 1, res = 0; if(x <= mid) res = query(rt, id<<1, x, y, l, mid) % p; if(mid < y) res = (res + query(rt, id<<1|1, x, y, mid + 1, r)) % p; return res; } } struct Oper { int op, l, r, x; } oper[100010]; int op_4[100010], cnt, cur; inline void process(int i, int rt, bool prt) { if(i <= 0) return; Oper op = oper[i]; if(op.op == 1) smt::adjust1(rt, 1, op.l, op.r, op.x, 1, n); else if(op.op == 2) smt::adjust2(rt, 1, op.l, op.r, op.x, 1, n); else if(op.op == 3 && prt) cout << smt::query(rt, 1, op.l, op.r, 1, n) << endl; } inline void init() { smt::build(0, 1, 1, n); smt::build(1, 1, 1, n); } int main() { cin >> n >> m; for(int i = 1; i <= n; i++) cin >> arr[i]; for(int i = 1; i <= m; i++) { cin >> oper[i].op; if(oper[i].op < 4) cin >> oper[i].l >> oper[i].r; if(oper[i].op < 3) cin >> oper[i].x; if(oper[i].op == 4) op_4[++cnt] = i; } init(); int cur_op_4 = 0; for(int i = 1; i <= m; i++) { int rev = op_4[cur_op_4] + op_4[cur_op_4 + 1] - i; if(oper[i].op == 4) { cur_op_4++; cur ^= 1; } else process(i, cur, true), process(rev, cur^1, false); } return 0; }
|