inlinevoidinsert(LL S){ int u = 1; for (int i = LOG - 1; i >= 0; --i) { int c = (S >> i) & 1; ++size[u]; if (!ch[c][u]) ch[c][u] = ++nidx; u = ch[c][u]; } ++size[u]; }
LL Qry(LL S, int k){ LL ret = 0; for (int u = 1, i = LOG - 1; i >= 0; --i) { int c = (S >> i) & 1; if (!ch[!c][u]) u = ch[c][u]; elseif (k <= size[ch[!c][u]]) u = ch[!c][u], ret |= 1LL << i; else k -= size[ch[!c][u]], u = ch[c][u]; } return ret; } }
intmain(){ #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); #endif // init Trie::init(); // input read(n), read(K), K <<= 1; for (int i = 1; i <= n; ++i) { static LL x; read(x), A[i] = A[i-1] ^ x; } // solve // 注意到要往 Trie 里塞个 0 for (int i = 0; i <= n; ++i) Trie::insert(A[i]); for (int i = 0; i <= n; ++i) PQ.push(Item(i, 1, Trie::Qry(A[i], 1))); LL ans = 0; while (K--) { Item u = PQ.top(); PQ.pop(); ans += u.s; if (u.k + 1 <= n) PQ.push(Item(u.u, u.k + 1, Trie::Qry(A[u.u], u.k + 1))); } // output printf("%lld\n", ans >> 1); return0; }
LL Toposort(){ static LL f[MAXV]; queue<int> Q; memset(f, 0, (uidx + 1) * sizeof (LL)); for (int i = 1; i <= uidx; ++i) if (!in[i]) Q.push(i); LL ret = 0; while (!Q.empty()) { int u = Q.front(); Q.pop(); ret = max(ret, f[u] + len[u]); for (int i = head[u]; ~i; i = edges[i].nxt) { int v = edges[i].to; f[v] = max(f[v], f[u] + len[u]); if (!(--in[v])) Q.push(v); } } for (int i = 1; i <= uidx; ++i) if (in[i]) return-1; return ret; } }
namespace SAM { int ch[MAXM][SIGMA], lnk[MAXM], nidx, last;
inlinevoidinsert(int val){ int nd = newnode(len[last] + 1), p = last; while (p && !ch[p][val]) ch[p][val] = nd, p = lnk[p]; if (!p) lnk[nd] = 1; else { int q = ch[p][val]; if (len[q] == len[p] + 1) lnk[nd] = q; else { int nxt = newnode(len[p] + 1); lnk[nxt] = lnk[q], memcpy(ch[nxt], ch[q], sizeof ch[nxt]); while (p && ch[p][val] == q) ch[p][val] = nxt, p = lnk[p]; lnk[q] = lnk[nd] = nxt; } } last = nd; }
voidbuild(){ for (int i = 1; i <= nidx; ++i) pre[0][i] = lnk[i]; for (int j = 1; j < LOG; ++j) for (int i = 1; i <= nidx; ++i) pre[j][i] = pre[j-1][pre[j-1][i]]; }
inlineintJump(int u, constint& lgt){ for (int j = LOG - 1; j >= 0; --j) if (pre[j][u] && len[pre[j][u]] >= lgt) u = pre[j][u]; return u; } }
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; } template<typename T> inlinevoidread(T& x, LL m){ x = 0; int f = 0, ch = Gc(); while (!isdigit(ch)) f |= ch == '-', ch = Gc(); while (isdigit(ch)) x = (x * 10LL + ch - '0') % m, ch = Gc(); if (f) x = -x; } } using IO::read;
namespace Solve1 { constint P = 998244353;
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; }
intmain(){ int n; read(n); for (int x, i = 1; i <= n; ++i) read(x, P-1), printf("%d\n", fpow(19, x)); return0; } }
namespace Solve2 { constint P = 1145141;
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; }
intmain(){ int n; read(n); for (int x, i = 1; i <= n; ++i) read(x, P-1), printf("%d\n", fpow(19, x)); return0; } }
namespace Solve3 { const LL P = 5211600617818708273;
inline LL plus(uLL a, uLL b){ return a + b >= P? a + b - P: a + b; } LL smul(LL base, LL b){ LL ret = 0; while (b > 0) { if (b & 1) ret = plus(ret, base); base = plus(base, base), b >>= 1; } return ret; } LL fpow(LL base, LL b){ LL ret = 1; while (b > 0) { if (b & 1) ret = smul(ret, base); base = smul(base, base), b >>= 1; } return ret; }
intmain(){ int n; read(n); for (int x, i = 1; i <= n; ++i) read(x), printf("%lld\n", fpow(19, x)); return0; } }
namespace Solve4 { constint P = 998244353, BEG = 55244, LOOP = 45699;
int n, A[BEG + LOOP + 1];
intmain(){ A[0] = 1; for (int i = 1; i <= BEG + LOOP; ++i) A[i] = 19 * A[i-1] % P; read(n); LL x; while (n--) read(x), printf("%d\n", A[x < BEG? x: (x - BEG) % LOOP + BEG]); return0; } }
namespace MillerRabin { LL fpow(LL base, LL b, LL m){ LL ret = 1; while (b > 0) { if (b & 1) ret = __int128(ret) * base % m; base = __int128(base) * base % m, b >>= 1; } return ret % m; }
boolisPrime(LL p, int L = 2){ if (p == 2 || p == 3) returntrue; if (p < 2 || p % 2 == 0) returnfalse; for (int a = 2; a <= L; ++a) { if (fpow(a, p-1, p) != 1) returnfalse; LL t, k = p - 1; while (!(k & 1)) { k >>= 1, t = fpow(a, k, p); if (t != p-1 && t != 1) returnfalse; if (t == p-1) break; } } returntrue; } } using MillerRabin::isPrime;
namespace Solve5 { intmain(){ int n; read(n); while (n--) { static LL L, R; read(L), read(R); for (LL i = L; i <= R; ++i) putchar(isPrime(i, 3)? 'p': '.'); putchar('\n'); } return0; } }
namespace Solve6 { constint MAXN = 1e6 + 5;
int n; LL L, R, A[MAXN];
bool notPrime[MAXN]; int mu[MAXN], Prime[MAXN], tot;
voidEulerSieve(){ notPrime[1] = true; for (int i = 2; i < MAXN; ++i) { if (!notPrime[i]) Prime[++tot] = i; for (int j = 1; j <= tot && i*Prime[j] < MAXN; ++j) { notPrime[i*Prime[j]] = true; if (i % Prime[j] == 0) break; } } }
int n, p, L, R; int fact[MAXM], tot; int vis[MAXN], lg[MAXN];
voidprime(int x){ tot = 0; for (int i = 2; i*i < x; ++i) if (x % i == 0) { fact[++tot] = i; while (x % i == 0) x /= i; } if (x > 1) fact[++tot] = x; } intfpow(int base, int b, int m){ int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * base % m; base = 1LL * base * base % m, b >>= 1; } return ret % m; }
boolisroot(int g){ for (int i = 1; i <= tot; ++i) if (fpow(g, (p - 1) / fact[i], p) == 1) returnfalse; returntrue; }
intmain(){ read(n); while (n--) { read(L), read(R); if (R != 234133333) read(p); else p = 1515343657; prime(p - 1); if (p == 13123111) { for (int j = 1; j <= tot; ++j) for (int i = 1; i <= (p-1) / fact[j]; ++i) vis[i * fact[j]] = 1; // 6 为 13123111 原根 for (int x = 6, i = 1; i < p; ++i, x = 6LL * x % p) lg[x] = i; for (int i = L; i <= R; ++i) putchar(vis[lg[i]]? '.': 'g'); } elsefor (int i = L; i <= R; ++i) putchar(isroot(i)? 'g': '.'); putchar('\n'); } return0; } }
constint MAXL = 32; char cmd[MAXL];
intmain(){ #ifndef ONLINE_JUDGE freopen("output.out", "w", stdout); #endif scanf("%s", cmd); if (cmd[0] == '1') { if (cmd[1] == '_') return Solve1::main(); if (cmd[1] == '?') { if (cmd[2] == '+') return Solve3::main(); return Solve2::main(); } if (cmd[1] == 'w') return Solve4::main(); } if (cmd[0] == '2') { if (cmd[1] == 'p') return Solve5::main(); if (cmd[1] == 'u') return Solve6::main(); if (cmd[1] == 'g') return Solve7::main(); } return0; }