text
stringlengths
49
983k
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int Read() { int x(0); char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar(); return x; } const int maxn = 1e5 + 9, mod = 998244353, maxm = 409; in...
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y) { long long res = 1; while (y) { if (y & 1) res = (res * x) % 998244353; y = y / 2, x = (x * x) % 998244353; } return res % 998244353; } long long n, k; const long long BLSZ = 300; long long NUMBL; inline long long g...
#include <bits/stdc++.h> using namespace std; int blkbase[(350 + 5)][(350 + 5)]; int blkpsum[(350 + 5)][(350 + 5)]; int f[100005]; int n, k; int a[100005]; int previ[100005]; int previval[100005]; int blk[100005]; int blkbegin[100005]; int blkend[1000005]; int cur[100005]; int cur_offset[(350 + 5)]; int cur_cnt[(350 + ...
#include <bits/stdc++.h> using namespace std; const int M = 205; const int N = 100005; const int L = 100000; const int mod = 998244353; int n, k, len, a[N], bel[N], pre[N], las[N], dp[N], fl[N], tot[N], ans[M], s[M][N << 1]; void ad(int i, int x) { (s[bel[i]][L + tot[i]] += mod - dp[i]) %= mod; tot[i] += x; (...
#include <bits/stdc++.h> using namespace std; long long mod = 998244353LL; int kk; class Block { public: int aux; vector<long long> pre; int st, en; int lo, hi; vector<long long> vals; vector<int> dist; Block(int a, int b) { aux = 0; st = a; en = b; lo = 0; hi = 0; pre.push_back(0...
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const int ms = 110000; const int bs = 1000; const int MOD = 998244353; void add(int &a, int b) { a = a + b < MOD ? a + b : a + b - MOD; } int *pivot; bool comp(int x1, int x2) { return pivot[x1] < pivot[x2]...
#include <bits/stdc++.h> using namespace std; const int magic = 404, mod = 998244353, maxn = 100000; int n, k, pre[111111], a[111111], cur[111111], dp[111111], b[111111]; int pr[255][222222], d[333]; void add(int &x, int y) { x += y; if (x < 0) x += mod; if (x >= mod) x -= mod; } void Add(int l, int r, int R) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 9, mod = 998244353, maxm = 409; int n, k, ans; int a[maxn], cnt[maxn], lst[maxn], fir[maxn], bl[maxm], br[maxm], col[maxn], v[maxn], lazy[maxm], f[maxn], sum[maxm][maxn]; inline void Fir() { int size(sqrt(n)); int pieces(ceil(1.0 * n / size));...
#include <bits/stdc++.h> using namespace std; const int BASE = 998244353; const int SZ = 320; struct BlockData { int sumC; vector<long long> sumF; BlockData() {} }; int n, k, c[100100]; long long f[100100]; BlockData blocks[SZ]; long long calc(int i) { long long res = 0; int sumC = 0, block = i / SZ; for (i...
#include <bits/stdc++.h> using namespace std; inline int Read() { int x(0); char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar(); return x; } const int maxn = 1e5 + 9, mod = 998244353, maxm = 409; int n, k, ans; int a[maxn]...
#include <bits/stdc++.h> using namespace std; const int MOD = 119 << 23 | 1; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b...
#include <bits/stdc++.h> using namespace std; const int P = 998244353; const int N = 101000, B = 340; int n, b, c, kk; int a[N], ans[N], lst[N], prv[N], tag[N]; void add(int& x, int y) { if ((x += y) >= P) x -= P; } struct Block { int ptr, ans; int v[N]; void set(int j) { if (tag[j] <= ptr) add(ans, ::ans[j...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; void add(int &a, int b) { a += b; if (a >= MOD) { a -= MOD; } if (a < 0) { a += MOD; } } struct FenwickTree { int dat[100055]; FenwickTree() { memset(dat, 0, sizeof(dat)); } void add(int id, int val) { while (id <= (int...
#include <bits/stdc++.h> using namespace std; int n, k, unit, tot; int be[(100005)], st[(100005)], en[(100005)], a[(100005)], sum[2055][2055], f[(100005)], pre[(100005)], now[(100005)], lazy[(100005)], S[(100005)]; const int P = 998244353; template <typename T> void read(T& t) { t = 0; bool fl = true; char p ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("fast-math") using namespace std; long long MOD = 998244353; long long ans[100007]; int a[10000...
#include <bits/stdc++.h> using namespace std; template <class X, class Y> void amax(X &x, const Y &y) { if (x < y) x = y; } template <class X, class Y> void amin(X &x, const Y &y) { if (x > y) x = y; } const int INF = 1e9 + 10; const long long INFL = (long long)1e18 + 10; const int MAX = 1e5 + 10; const int MAXS = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5, B = 350, Mod = 998244353; int n, lim, siz, block_cnt, cnt[maxn], a[maxn], b[maxn], sum_b[1005], sum_f[1005][1005], f[maxn]; vector<int> pos[maxn]; void cal(int w) { memset(sum_f[w], 0, sizeof sum_f[w]); int tmp = 0; for (int i = w * siz; ...
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long b, long long mod = (long long)(1e9 + 7)) { if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const...
#include <bits/stdc++.h> using namespace std; const int Mod = 998244353; int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; } void Add(int &a, int b) { a = add(a, b); } int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; } void Dec(int &a, int b) { a = dec(a, b); } const int N = 1e5 + 50, M ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 5; const int M = 505; const ll mod = 998244353; ll add(ll a, ll b) { return (a + b >= mod ? a + b - mod : a + b); } ll sub(ll a, ll b) { return (a - b < 0 ? a - b + mod : a - b); } ll mul(ll a, ll b) { return (a * b) % mod; } int n,...
#include <bits/stdc++.h> const int N = 100005, B = 320, M = 998244353; using namespace std; int n, k, ti, a[N], occ[N], pre[N], b[N], f[N], sum[B], q[B][B << 1 | 1], now; inline void mdf(int x, int y) { b[x] = y; int z = x / B; if (z == now) return; sum[z] = 0; for (int i = 0; i <= B << 1; i++) q[z][i] = 0; ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC optimize("unroll-loops") using namespace std; const int block = 320, nax = 100005, mod = 998244353; inline int add(int x, int y) { return (x += y) < mod ? x : x - mod; } inline int sub(int x, int y) { return (x -= y) >= 0 ? x : x + mo...
#include <bits/stdc++.h> const int N = 1e5 + 5, M = N / 160 + 3; int bel[N], f[N], g[N], tag[M], s[M][160 + 3 << 1]; inline int read() { int now = 0; register char c = getchar(); for (; !isdigit(c); c = getchar()) ; for (; isdigit(c); now = now * 10 + c - 48, c = getchar()) ; return now; } void Update...
#include <bits/stdc++.h> using namespace std; long long MOD = 998244353; long long mpow(long long a, long long b) { if (b == 0) return 1; long long t1 = mpow(a, b / 2); t1 *= t1; t1 %= MOD; if (b % 2) t1 *= a; t1 %= MOD; return t1; } const long long N = 1e5 + 5; const long long block = 320; vector<long lo...
#include <bits/stdc++.h> using namespace std; inline int Read() { int x(0); char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar(); return x; } const int maxn = 1e5 + 9, mod = 998244353, maxm = 409; int n, k, ans; int a[maxn]...
#include <bits/stdc++.h> using namespace std; const int P = 998244353; int n, k; inline int ad(int& x, int& y) { return (x + y > P ? x + y - P : x + y); } int A[200006], las[200006], pr[200006]; const int blo = 133; int bel[200006]; pair<int, int> B[200006]; int S[200006]; int val[200006], gv[200006], lz[200006], cur; ...
#include <bits/stdc++.h> namespace _ { const int inf = 1e9; const int mod = 998244353; const double eps = 1e-8; namespace IO_IN { char buf[1 << 23], *p1 = buf, *p2 = buf; int getc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 23, stdin), p1 == p2) ? EOF : *p1++; } template <cl...
#include <bits/stdc++.h> using namespace std; int N, B, K, C = 500; int delta[1005]; long long tbl[1005][1005]; int lst1[100005], lst2[100005]; int val[100005]; long long dp[100005]; long long MOD = 998244353; long long add(long long a, long long b) { return (a + b) % MOD; } long long sub(long long a, long long b) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005, maxm = 320, tt = 998244353; int n, m, n1, a[maxn], f[maxn], g[maxm][maxn], bl[maxn], sq, val[maxn], tag[maxm]; int L[maxn], R[maxn]; int las[maxn], las1[maxn]; void build(int x, int l, int r) { for (int i = l; i <= r; i++) { g[x][val[i]] =...
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const int ms = 110000; const int bs = 400; const int MOD = 998244353; void add(int &a, int b) { a = a + b < MOD ? a + b : a + b - MOD; } int *pivot; bool comp(int x1, int x2) { return pivot[x1] < pivot[x2];...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int MAXN = 100005; const int Blocks = 405; int n, qk, a[MAXN], pre[MAXN], lst[MAXN], dp[MAXN], f[MAXN]; int sum[Blocks][MAXN], ans[Blocks], lz[Blocks], l[Blocks], r[Blocks], bl[MAXN]; inline void add(int &x, int y) { x += y; (x >= mod) &...
#include <bits/stdc++.h> const int maxn = 100005, mod = 998244353, maxt = 325; int n, k, t; int a[maxn], l[maxt], r[maxt], pos[maxn], lst[maxn], pre[maxn], f[maxn], sum[maxt][maxn], tot[maxn], tag[maxt], cnt[maxn]; void BF(int x, int y, int v) { for (int i = x; i <= y; i++) { if (v == 1) cnt[i]++, sum[p...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2") using namespace std; using ll = long long; int a[101001]; int b[101010]; int dp[101010]; int p1[101010]; int p2[101010]; ll ans = 0; int n, k; void add(int* __restrict a, int* __restrict dp, int n) { for (int i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; int n, m, h[N], lev[N], Xor[N], cnt[N], deg[N]; vector<int> nxt[N], rnxt[N], vec[N]; set<int> s; queue<int> q; int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y...
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000000010LL; const int mod = 1000000007; const int MAXN = 200010, LOG = 20; int n, m, k, u, v, x, y, t, a, b, ans; int A[M...
#include <bits/stdc++.h> using namespace std; int he[200010], ver[2 * 200010], nxt[2 * 200010], tot, in[200010]; void add(int x, int y) { ver[++tot] = y; nxt[tot] = he[x]; he[x] = tot; } int que[200010], cnt; long long w[200010]; vector<int> v[200010]; long long ans[200010]; int s[200010]; bool vis[200010]; int m...
#include <bits/stdc++.h> using namespace std; using i64 = long long; int n, m, h[223456], xors[223456], sg[223456], tag[223456]; int u, v, t, deg[223456], q[223456]; vector<int> e[223456]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &h[i]); } for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; vector<int> e[N]; int n, m, h[N], sg[N], sum[N], dg[N], q[N], vis[N]; void topsort() { int h = 1, t = 0; for (int i = 1; i <= n; i++) if (!dg[i]) q[++t] = i; while (h <= t) { int u = q[h++]; for (int v : e[u]) if (!--dg[v]) q[...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, y = 0, c = getchar(); while (!isdigit(c)) y = c, c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar(); return y == '-' ? -x : x; } inline void print(long long q) { if (q < 0) putchar('-'), ...
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; long long ln, lk, lm; void etp(b...
#include <bits/stdc++.h> using namespace std; long long head[400005], ver[400005], nxt[400005], cnt; void add(long long a, long long b) { ver[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt; } vector<long long> e[400005], has[400005]; long long n, m, cd[400005]; long long a[400005], sg[400005]; long long pos[400005], m...
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int kMaxN = 2e5 + 3; vector<int> edges[kMaxN]; bitset<kMaxN> visited; int nim[kMaxN]; int mext[kMaxN]; int levels[kMaxN]; vector<int> nim_nodes[kMaxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m; bool tmp[N]; int h[N], f[N], b[N]; vector<int> G[N]; int deg[N]; vector<int> ord; void topusort() { queue<int> Q; for (int i = 1; i <= n; i++) { if (!deg[i]) { Q.push(i); } } while (!Q.empty()) { int p = Q.front(); ...
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 10; int n, m, clk; int h[maxN + 1], vis[maxN + 1]; int p[maxN + 1], sum[maxN + 1]; vector<int> G[maxN + 1]; inline int read() { int num = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } ...
#include <bits/stdc++.h> const int N = 200007; int a[N], deg[N], pos[N], vis[N], sg[N], sum[N]; std::queue<int> q; std::vector<int> e[N]; int read() { int x = 0, c = getchar(); while (isspace(c)) c = getchar(); while (isdigit(c)) (x *= 10) += c & 15, c = getchar(); return x; } int main() { int n = read(), m =...
#include <bits/stdc++.h> inline void read(int& x) { char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); } const int N = 201000; struct Edge { int v, nxt; } a[N + N]; int head[N], Head[N]; int h[N], xr[N], deg[N], q[N]; int tng[N], sg[N]; ...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > adj(200001); int c[200001], mex[200001], h[200001], b[200001]; void DFS(int i) { if (mex[i] >= 0) { return; } vector<int> v; for (int j : adj[i]) { DFS(j); v.push_back(mex[j]); } for (int x : v) { c[x] = i; } int &k = mex...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5; int n, m, h[maxn + 3], xo[maxn + 3], deg[maxn + 3], sg[maxn + 3], vis[maxn + 3], res[maxn + 3]; vector<int> G[maxn + 3], H[maxn + 3]; int main() { scanf("%d %d", &n, &m); for (int i = (1); i <= int(n); i++) scanf("%d", &h[i]); for (int i = (1...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; struct edge { int to, nxt; }; edge G[maxn]; int head[maxn], cnt; int h[maxn], deg[maxn]; queue<int> Q; int a[maxn]; bool vis[maxn]; int bel[maxn]; int nim[maxn]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) sca...
#include <bits/stdc++.h> using namespace std; int n, m; int a[200000 + 5]; vector<int> E[200000 + 5]; int ind[200000 + 5]; int rk[200000 + 5]; int sg[200000 + 5]; void topo() { static bool vis[200000 + 5]; queue<int> q; vector<int> seq; for (int i = 1; i <= n; i++) if (ind[i] == 0) q.push(i); while (!q.em...
#include <bits/stdc++.h> using namespace std; const int MaxN = 2e5 + 100; int stack_sizes[MaxN]; vector<int> adj[MaxN]; int N, M; int vertex_group_idx[MaxN]; bool visited[MaxN]; int group_xor[MaxN]; vector<int> vertex_groups[MaxN]; void DfsMakeLayers(int vert) { visited[vert] = true; vector<int> seen_layers; for ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 10; const ll inf_ll = 1e18 + 10; const int N = 2e5 + 5; int h[N], f[N], l[N], v[N]; vector<int> adj[N]; void dfs(int i) { v[i] = 1; vector<int> d; for (auto& j : adj[i]) { if (!v[j]) dfs(j); d.push_back(l[j]); } ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; bool t = false; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') t = true, ch = getchar(); while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar(); return t ? -x : x; } v...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<vector<int>> adj(n); vector<int> deg(n); for (int i = 0; i < m; ++i) { int from, t...
#include <bits/stdc++.h> using namespace std; int T, n, m, head[200010], o = 0, deg[200010], id[200010], val[200010], a[200010]; bool vis[200010]; queue<int> q; struct edge { int to, link, w; } e[400010]; void add_edge(int u, int v) { e[++o].to = v, e[o].link = head[u], head[u] = o, e[o]....
#include <bits/stdc++.h> using namespace std; int n, m, a[200005], in[200005], tag[200005], sg[200005], sum[200005]; vector<int> Ef[200005], Eb[200005], tt[200005]; queue<int> q; void tpsort() { for (int i = 1; i <= n; i++) if (!in[i]) q.push(i), tt[0].push_back(i); while (!q.empty()) { int x = q.front(); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; vector<int> ve1[maxn], ve2[maxn]; int rd[maxn]; int n, m; int sm[maxn], h[maxn]; queue<int> q; int mx[maxn]; int vis[maxn]; vector<int> veo[maxn]; bool mark[maxn]; void ptans() { for (int i = 1; i <= n; i++) { printf("%d ", h[i]); } } int m...
#include <bits/stdc++.h> using namespace std; int h[200000]; vector<int> node[200000]; int done[200000]; vector<int> topo; void dfs(int p) { if (done[p]++) return; for (int i : node[p]) { dfs(i); } topo.push_back(p); } int grundy[200000]; int grundy2[200000]; int main() { ios::sync_with_stdio(0); cin.ti...
#include <bits/stdc++.h> using namespace std; int read() { bool f = 1; int x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = 0; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3) + (x << 1) - 48 + c; c = getchar(); } return f ? x : x * -1; } char cr[200]...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int rd() { int x = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + (ch ^ 48); ch = getchar(); } return x * w; } int to[N], nt[N...
#include <bits/stdc++.h> using namespace std; const int maxik = 2e5 + 10; int g[maxik]; vector<int> rodes[maxik]; void dfs(int curr) { bool us[rodes[curr].size() + 1]; memset(us, 0, rodes[curr].size() + 1); for (int i = 0; i < rodes[curr].size(); i++) { int neighbour = rodes[curr][i]; if (g[neighbour] == ...
#include <bits/stdc++.h> const int max_N = 202401; int n, m, A[max_N], topo[max_N], mex[max_N], xor_sum[max_N]; std::vector<int> G[max_N]; int read_int() { char c = getchar(); int ans = 0; bool neg = false; while (!isdigit(c)) neg |= (c == '-'), c = getchar(); while (isdigit(c)) ans = 10 * ans + c - '0', c = ...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2; vector<int> adj[N], in[N], idx[N]; int mex[N], val[N], h[N], deg[N]; bool used[N]; queue<int> lis; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, i, j, k, l, max1; cin >> n >> m; for (i = 1; i <= n; i++) { cin >> h[i]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; struct edge { int to, nxt; }; edge G[maxn]; int head[maxn], cnt; int h[maxn], deg[maxn]; queue<int> Q; int a[maxn]; bool vis[maxn]; int bel[maxn]; int nim[maxn]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) sca...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, N = 210000; int n, m, dgr[N], cnt, rev[N], lev[N]; long long a[N], sum[N]; vector<int> to[N], pos[N]; priority_queue<int, vector<int>, greater<int> > que; inline void addEdg(int x, int y) { to[x].push_back(y), ++dgr[y]; return; } void topoSort...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 200010; i...
#include <bits/stdc++.h> using namespace std; const int N = 200010, M = 200010; int n, m; int e, to[M], nxt[M], hd[N], deg[N]; int tag[N], sg[N], val[N], sum[N]; vector<int> vec[N]; void add(int x, int y) { to[++e] = y; nxt[e] = hd[x]; hd[x] = e; } void topo() { queue<int> q; for (int i = 1; i <= n; i++) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n, m; int h[maxn], in[maxn], q[maxn], sg[maxn], sum[maxn], vis[maxn]; vector<int> G[maxn]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%d", &h[i]); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d%d",...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, eid, cnt, p[N], h[N], d[N], vis[N], sg[N], sum[N], b[N]; struct edge { int V, nxt; } e[N << 1]; inline void addedge(int u, int v) { e[++eid] = (edge){v, p[u]}, p[u] = eid; } inline void tuopu() { queue<int> q; while (!q.empty()) q.pop(...
#include <bits/stdc++.h> using namespace std; inline int read() { int w = 1, s = 0; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return w * s; } int n, m, h[1001000], Sum[1010010], Sg[101...
#include <bits/stdc++.h> using namespace std; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr; inline void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; } inline void putc(ch...
#include <bits/stdc++.h> const int N = 200200; using namespace std; int n; int q; int h[N]; int m[N]; int t[N]; vector<int> v[N]; void dfs(int x) { if (t[x]) { return; } set<int> s; for (int y : v[x]) { dfs(y); s.insert(t[y]); } t[x] = 1; while (s.find(t[x]) != s.end()) { t[x] += 1; } } ...
#include <bits/stdc++.h> using namespace std; int read(); int n, m; vector<int> e[200005]; int deg[200005]; void add(int f, int t) { e[f].push_back(t), ++deg[t]; } queue<int> q; int h[200005], sg[200005], mx, sum[200005]; vector<int> nx[200005]; void work() { for (int i = 1; i <= n; ++i) if (!deg[i]) q.push(i); ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, h[N], q[N], d[N], s[N], vis[N], sg[N]; vector<int> g[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); g[u].push_back(v);...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; vector<int> E[N]; int n, m, h[N], deg[N], vis[N], sg[N], sum[N], sq[N], tt = 0; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1, u, v; i <= m; i++) cin >> u >> v, ++deg[v], E[u].push_back(v); queue<int> q;...
#include <bits/stdc++.h> using namespace std; int v[500500]; vector<int> L[500500]; int xl[500500]; int lvl[500500]; void go(int x) { if (lvl[x]) return; map<int, int> mp; for (int i = 0; i < L[x].size(); i++) { go(L[x][i]); mp[lvl[L[x][i]]] = 1; } lvl[x] = 1; while (mp[lvl[x]]) lvl[x]++; xl[lvl[x...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 1; int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x; } vector<int> to[maxn]; int h[maxn], SG[maxn], sum[maxn]; int c[maxn], deg...
#include <bits/stdc++.h> using namespace std; const int maxn = 200500; vector<int> side[maxn]; int n, m, val[maxn]; long long h[maxn], x[maxn], mx; void dfs(int u) { if (val[u] != -1) return; bool vis[705] = {0}; for (int i = 0; i < side[u].size(); i++) { int v = side[u][i]; dfs(v); vis[val[v]] = 1; ...
#include <bits/stdc++.h> using namespace std; inline long long read() { register long long x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, m, i, j, t, k, s, head[maxn], N, in[maxn], b[maxn], sg[maxn]; long long a[maxn], val[maxn]; bool vis[maxn]; struct Edge { int nxt, aim; } edge[maxn]; inline void add_edge(int x, int y) { edge[++N] = (Edge){head[x], y}; head[x] = N; } qu...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a[200005]; struct edge { int to, nxt; } e[200005]; int hed[200005], cnt; inline void add(int u, int v) { e[++cnt] = (edge){v, hed[u]}; hed[u] = cnt; } int num[200005], ru[200005]; int sg[200005], tag[200005], dep[200005]; inline void topo() { q...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { int f = 0; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f |= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } const int N = 200005; int h[N], q[N], dp[N], in[...
#include <bits/stdc++.h> using namespace std; const int Q = 1 << 18; struct gra { int las[Q], e[Q], nn[Q], inc; void ins(int x, int y) { e[++inc] = y; nn[inc] = las[x]; las[x] = inc; } } g, f; int mex[Q]; int vis[Q]; int h[Q], sm[Q]; int q[Q]; int in[Q]; int main() { int n, m; scanf("%d%d", &n, &m...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &item) { out << '(' << item.first << ", " << ite...
#include <bits/stdc++.h> using namespace std; int level[200005]; int h[200005]; int val[200005]; bool vis[200005]; bool num[200005]; vector<int> E[200005]; void dfs(int x) { if (vis[x]) return; vis[x] = true; if (E[x].size() == 0) level[x] = 0; int sz = E[x].size(); for (int v : E[x]) { if (!vis[v]) { ...
#include <bits/stdc++.h> using namespace std; long long n, m, num[200100], sy[200100], ds[200100], bj[200100], sum[200100]; vector<long long> to[200100], pre[200100]; queue<long long> que; int main() { long long i, j, t, p, q; cin >> n >> m; for (i = 1; i <= n; i++) scanf("%lld", &num[i]); for (i = 1; i <= m; i...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = v * 10 + c - '0'; while (isdigit(c = getchar())) v = v * 10 + c - '0'; x = v * f; } inline void read(long lon...
#include <bits/stdc++.h> using namespace std; int n, m, a[200009], h[200009], q[200009], d[200009], s[200009], sg[200009], bo[200009]; vector<int> e[200009]; bool vis[200009]; int read() { int x = 0; char ch = getchar(); bool flag = 0; while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = get...
#include <bits/stdc++.h> using namespace std; using vint = vector<long long>; using pint = pair<long long, long long>; using vpint = vector<pint>; template <typename A, typename B> inline void chmin(A& a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A& a, B b) { if (a < b) a = b; }...
#include <bits/stdc++.h> using namespace std; int n, m; int h[200200]; struct data { int to, nxt; } mp[200200]; int head[200200], cnt; void link(int x, int y) { mp[++cnt].to = y; mp[cnt].nxt = head[x]; head[x] = cnt; } int d[200200]; queue<int> q; vector<int> nx[200200]; int id[200200]; int val[200200]; void To...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; bool flg = false; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') flg = true; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return flg ? -x : x; } int n, m, h[200010], g[200010]; vec...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5, maxm = 2e5 + 5; int head[maxn], nume; struct edge { int v, w, c, next; } e[maxm]; inline void init_edge() { memset(head, -1, sizeof head); nume = 0; } inline void add_edge(int u, int v, int w = 0, int c = 0) { e[nume].v = v; e[nume].w = w...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(register T& t) { register T f = 1; register char ch = getchar(); t = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar(); t ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; vector<int> G[maxn]; int topo[maxn]; int sg[maxn], deg[maxn], mem[maxn]; int Xor[maxn]; long long h[maxn]; int main(void) { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) scanf("%lld", &h[i]); for (int i = 1; i <= m; ++i) { int ...
#include <bits/stdc++.h> std::vector<std::vector<int>> ad; std::vector<int> fm; std::vector<bool> tmp; int f(int x) { if (fm[x] >= 0) return fm[x]; for (int y : ad[x]) f(y); for (int y : ad[x]) tmp[fm[y]] = true; fm[x] = int(std::find(begin(tmp), end(tmp), false) - begin(tmp)); for (int y : ad[x]) { tmp[f...
#include <bits/stdc++.h> using namespace std; const int maxn = 200500; vector<int> side[maxn]; int n, m, val[maxn]; long long h[maxn], x[maxn], mx; void dfs(int u) { if (val[u] != -1) return; bool vis[705] = {0}; for (int i = 0; i < side[u].size(); i++) { int v = side[u][i]; dfs(v); vis[val[v]] = 1; ...
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); } f ...
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } tem...