inlineintGc(){ return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)? EOF: *p1++; } template<typename T> inlinevoidread(T& x){ x = 0; int f = 0, ch = Gc(); while (!isdigit(ch)) f |= ch == '-', ch = Gc(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = Gc(); if (f) x = -x; } } using IO::read;
constint MAXQ = 1e5 + 5, P = 1e7 + 19;
structOpt { int opt, idx, val; } Q[MAXQ];
int n, q, t, ans; int inv[P]; unordered_map<int, int> A;
inlinevoidsolve(const Opt& p){ staticint a = 1, b = 0, c = 0, s = 0; if (p.opt == 1) { if (A.count(p.idx) > 0) s = (s - (1LL * a * A[p.idx] % P + b) % P + P) % P; else s = (s - (1LL * a * c % P + b) % P + P) % P; A[p.idx] = 1LL * (p.val - b + P) % P * inv[a] % P; s = (s + p.val) % P; } if (p.opt == 2) b = (b + p.val) % P, s = (s + 1LL * n * p.val) % P; if (p.opt == 3) { a = 1LL * a * p.val % P, b = 1LL * b * p.val % P; s = 1LL * s * p.val % P; } if (p.opt == 4) { a = 1, b = 0, c = p.val, s = 1LL * n * p.val % P; A.clear(); } if (p.opt == 5) { if (A.count(p.idx) > 0) ans = (ans + (1LL * a * A[p.idx] % P + b) % P) % P; else ans = (ans + (1LL * a * c % P + b) % P) % P; } if (p.opt == 6) ans = (ans + s) % P; }
intmain(){ #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); #endif // input read(n), read(q); for (int i = 1; i <= q; ++i) { staticint opt, idx, val; read(opt), idx = val = 0; if (opt == 1 || opt == 5) read(idx); if (opt != 5 && opt != 6) read(val); Q[i] = (Opt){ opt, idx, (val % P + P) % P }; } // init inv[0] = inv[1] = 1; for (int i = 2; i < P; ++i) inv[i] = 1LL * inv[P % i] * (P - P / i) % P; // output read(t); while (t--) { staticint a, b; read(a), read(b); for (int j = 1; j <= q; ++j) solve(Q[(a + 1LL * j * b % q) % q + 1]); } printf("%d\n", ans); return0; }
intfpow(int base, int b){ int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * base % P; base = 1LL * base * base % P, b >>= 1; } return ret; }
voidexgcd(int a, int b, int& x, int& y){ if (!b) x = 1, y = 0; elseexgcd(b, a % b, y, x), y -= a / b * x; } inlineintinv(constint& a){ staticint x, y; returnexgcd(a, P, x, y), (x % P + P) % P; }
namespace SDOI { int n, a, b, c, s; unordered_map<int, int> A;
inlinevoidinit(int _n){ n = _n, a = 1, b = c = s = 0, A.clear(); }
inline LL Qry(){ return s; } inline LL Qry(constint& p){ return (1LL * a * ((A.count(p) > 0)? A[p]: c) % P + b) % P; } inlinevoidSgn(constint& v){ a = 1, b = 0, c = v, s = 1LL * n * v % P, A.clear(); } inlinevoidSgn(constint& p, constint& v){ s = (s - (1LL * a * ((A.count(p) > 0)? A[p]: c) % P + b) % P + P) % P; A[p] = 1LL * (v - b + P) % P * inv(a) % P, s = (s + v) % P; } inlinevoidAdd(constint& v){ b = (b + v) % P, s = (s + 1LL * n * v % P) % P; } inlinevoidMul(constint& v){ if (!v) returnSgn(v); a = 1LL * a * v % P, b = 1LL * b * v % P, s = 1LL * s * v % P; } } using SDOI::Sgn; using SDOI::Add; using SDOI::Mul; using SDOI::Qry;
voidMatrixMul(constint* f, int* g, constint (*W)[5]){ for (int i = 0; i < 5; ++i) for (int j = 0; j < 5; ++j) g[i] = (g[i] + 1LL * f[j] * W[i][j] % P) % P; }
int n, m, C; int A[MAXN], B[MAXN]; int pos[MAXN], g[MAXN][5];
voidPreMatrix(){ int x = C - 2, y = C - 3, yy = 1LL * y * y % P, xy = 1LL * x * y % P; constint W[5][5] = { { 0, 1, 0, 2*x, xy }, { 1, 0, 2*x, 0, xy }, { 0, 1, x, x+y, yy }, { 1, 0, x+y, x, yy }, { 1, 1, 2*y, 2*y, int((C * (C - 7LL) + 13) % P) } }; g[0][0] = 1; for (int i = 1; i <= n; ++i) MatrixMul(g[i - 1], g[i], W); }
structEdge { int u, v, w; Edge(int _u, int _v, int _w): u(_u), v(_v), w(_w) { } booloperator < (const Edge& rhs) const { return w < rhs.w; } };
int n, m, q, lim; unsigned SA, SB, SC;
vector<Edge> E; int Idx[MAXV], W1[MAXM][MAXN], W2[MAXM][MAXN];
namespace Graph { structEdge { int nxt, to, w; } edges[MAXV << 1]; int head[MAXV], eidx;
inlinevoidinit(int _n){ memset(head, -1, (_n + 1) * sizeof (int)), eidx = 1; } inlinevoidAddEdge(int from, int to, int w){ edges[++eidx] = (Edge){ head[from], to, w }, head[from] = eidx; edges[++eidx] = (Edge){ head[to], from, w }, head[to] = eidx; }
intdfsPre(int u, int fa, constint& tot){ int s = 0; for (int v, i = head[u]; ~i; i = edges[i].nxt) if ((v = edges[i].to) != fa) s += dfsPre(v, u, tot); if (s >= 2) Idx[u] = 1; return s + Idx[u] > 0; } voiddfs(int u, int fa, int lst, int w, LL& s){ if (Idx[u] > 0) { if (lst > 0) E.push_back(::Edge(Idx[lst], Idx[u], w)); lst = u, s -= w, w = 0; } for (int v, i = head[u]; ~i; i = edges[i].nxt) if ((v = edges[i].to) != fa) dfs(v, u, lst, max(w, edges[i].w), s); } }
namespace DSU { int fa[MAXV];
inlinevoidinit(constint& _n){ for (int i = 1; i <= _n; ++i) fa[i] = i; }
voidLively(){ staticint Rmv[MAXN], nR, p, limit; ++Time, limit = nR = 0, p = n; for (int u = 1; u <= n; ++u) p = min(p, f[u]), PQ.push(Item(f[u] = deg[u], u)); while (!PQ.empty()) { int u = PQ.top().u, d = PQ.top().d; PQ.pop(); if (d != f[u]) continue; if (p < d) p = d, limit = nR; Rmv[++nR] = u, vis[u] = Time; for (int v, i = Graph::head[u]; ~i; i = Graph::edges[i].nxt) { if (vis[v = Graph::edges[i].to] == Time) continue; PQ.push(Item(--f[v], v)); } } nA = 0, ++Time; for (int i = 1; i <= limit; ++i) vis[Rmv[i]] = Time; for (int u = 1; u <= n; ++u) if (vis[u] != Time) A[++nA] = u; }
voidAwkward(){ nB = 0, ++Time; for (int u = 1; u <= n; ++u) PQ.push(Item(f[u] = deg[u], u)); while (!PQ.empty()) { int u = PQ.top().u, d = PQ.top().d; PQ.pop(); if (d != f[u] || vis[u] == Time) continue; B[++nB] = u, vis[u] = Time; for (int v, i = Graph::head[u]; ~i; i = Graph::edges[i].nxt) { if (vis[v = Graph::edges[i].to] == Time) continue; vis[v] = Time; for (int x, j = Graph::head[v]; ~j; j = Graph::edges[j].nxt) if (vis[x = Graph::edges[j].to] != Time) PQ.push(Item(--f[x], x)); } } }
intmain(){ #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); #endif int Ti; read(Ti); while (Ti--) { // init Graph::init(); memset(deg, 0, sizeof deg); // input read(n), read(m); for (int u, v, i = 1; i <= m; ++i) { read(u), read(v); Graph::AddEdge(u, v), Graph::AddEdge(v, u); ++deg[u], ++deg[v]; } // solve Lively(), Awkward(); // output printf("%d ", nA); for (int i = 1; i <= nA; ++i) printf("%d%c", A[i], " \n"[i == nA]); printf("%d ", nB); for (int i = 1; i <= nB; ++i) printf("%d%c", B[i], " \n"[i == nB]); } return0; }