text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos((long double)-1.0); const double EPS = 1e-10; const int MOD = 1e9 + 7; template <typename T> void cmin(T &x, T y) { if (y < x) x = y; } template <typename T> void cmax(T &x, T ...
#include <bits/stdc++.h> using namespace std; int T, n, m, p, k, a[200010], pos[200010], bit[200010], hd; long long ans = 0; int query(int a) { int tmp = 0; for (int i = a; i >= 1; i -= (i & -i)) tmp += bit[i]; return tmp; } void add(int a, int x) { for (int i = a; i <= n; i += (i & -i)) bit[i] += x; } set<int>...
#include <bits/stdc++.h> using namespace std; const int maxd = 4e5 + 10; long long t1[maxd], t2[maxd], pos[maxd], a[maxd], n; void add(long long* t, long long x, long long v) { for (; x < maxd; x += (x & -x)) t[x] += v; } long long query(long long* t, long long x) { long long ans = 0; for (; x; x -= (x & -x)) ans...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (b == 0 ? a : gcd(b, a % b)); } char vow[] = {'a', 'e', 'i', 'o', 'u'}; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; const int N = 4e5 + 30; const long long int mod = -1e11; int n; int tx[N]; set<long lon...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 2e5 + 233; int ch[maxn]; int a[maxn], n, p[maxn]; long long ans[maxn], sum[maxn]; void add(int x, int v) { for (int i = x; i <= n; i += i & (-i)) ch[i] += v; } int query(int x) { int sum = 0; for (int i = x; i; i -= i & (-i)) ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 200000; long long a[200005], pos[200005]; long long sum1[200005], sum2[200005]; void add(long long *sum1, long long x, long long val) { while (x <= maxn) { sum1[x] += val; x += x & (-x); } } long long sum(long long *sum1, long long pos) { ...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using pii = pair<int, int>; using vii = vector<pii>; using ll = long long; int solve(); int main(int argc, char* argv[]) { ::std::ios::sync_with_stdio(false); ::std::cin.tie(0); ::std::cout.tie(0); int t = 1; while (t--) { solve(); } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int position[maxn]; long long sum1[maxn << 2], sum2[maxn << 2]; void add(long long* bit, int pos, long long val) { while (pos <= N) { bit[pos] += val; pos += pos & (-pos); } } long long query(long long* bit, int pos) { long lo...
#include <bits/stdc++.h> using namespace std; int n; int a[300005], pos[300005]; int lowbit(int now) { return now & (-now); } long long sum[5][300005]; void add(int flag, int now, int val) { for (int i = now; i <= n; i += lowbit(i)) sum[flag][i] += val; } long long query(int flag, int now) { long long ans = 0; fo...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos((long double)-1.0); const double EPS = 1e-10; const int MOD = 1e9 + 7; template <typename T> void cmin(T &x, T y) { if (y < x) x = y; } template <typename T> void cmax(T &x, T ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n; int a[MAXN]; int pos[MAXN]; struct BIT { long long tree[MAXN]; BIT() {} int LB(int x) { return x & -x; } void Modify(int p, long long k) { while (p <= n) { tree[p] += k; p += LB(p); } } long long Query(int p) ...
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 1000000007; long long qpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } stru...
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 1000000007; long long qpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } stru...
#include <bits/stdc++.h> using namespace std; const bool debug = true; int p[200001]; int pos[200001]; class seg_tree { int* st; int n; public: seg_tree(int a) { st = new int[2 * a]; for (int i = 0; i < 2 * a; i++) st[i] = 0; n = a; } void set(int x) { x += n; st[x] = 1; x /= 2; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1, base = (1 << 19); int n, p[N], inv_t[2 * base + 1], where[N], pref; long long pos_t[2 * base + 1]; void add(int pos) { pos += base; while (pos) { inv_t[pos]++; pos /= 2; } } int sum(int l, int r) { l += base; r += base; int res = i...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 10; int bit[MAX_N], n, pos[MAX_N], x; long long ans = 0; int lowbit(int x) { return x & (-x); } int sum(int x) { int res = 0; while (x < MAX_N) { res += bit[x]; x += lowbit(x); } return res; } void update(int x) { while (x) { bi...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int a[MAX], p[MAX], n; long long c1[MAX], c2[MAX]; set<int> st; void add(long long *c, int x, int k) { for (; x <= n; x += x & -x) c[x] += k; } long long query(long long *c, int x) { long long sum = 0; for (; x; x -= x & -x) sum += c[x]; ret...
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const int MAXN = 201010; int n, median; int v[MAXN]; int ind[MAXN]; long long st[4 * MAXN]; long long adjust[MAXN]; long long inversions[MAXN]; priority_queue<int> maxheap; priority_queue<int, vector<int>, greater<int> > minheap; void update(int ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long bit[N] = {}; int idx[N] = {}; int n; priority_queue<int> A; priority_queue<int, vector<int>, greater<int>> B; inline long long __abs(int x) { return (x ^ (x >> 31)) - (x >> 31); } long long sum(int x) { int ret = 0; while (x) { ret +...
#include <bits/stdc++.h> const int inf = (1 << 29) - 1; const int maxn = (int)2e5 + 10; const int mod = (int)1e9 + 7; using namespace std; int n; int p[maxn]; long long t[2][maxn]; int rp[maxn]; void upd(int id, int pos, int val) { for (int i = pos; i <= n; i |= i + 1) t[id][i] += val; } long long get(int id, int pos...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9; long long mid[N], a[N], mark[N], k, f1[N][2], n, g[N], h[N], p, ct, cn, tvn = 1, tedad[N * 4]; string s, s2; long long saghf(long long x) { return (x / 2) + (x % 2); } string binary(int m, int k) { string g = ""; for (long long i = 0; i < k; i...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long bit[N] = {}; int idx[N] = {}; int n; priority_queue<int> A; priority_queue<int, vector<int>, greater<int>> B; long long sum(int x) { int ret = 0; while (x) { ret += bit[x]; x -= (x & -x); } return ret; } void add(int x, int v...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; int pos[maxn]; long long sum1[maxn], sum2[maxn]; int lowbit(int x) { return x & -x; } void add(long long *sum, int x, long long v) { while (x <= n) { sum[x] += v; x += lowbit(x); } } long long query(long long *sum, int x) { lo...
#include <bits/stdc++.h> using namespace std; long long ans, n, a[210000], x, sum1, sum2, las; int rd[450000], siz[450000], son[450000][2], v[450000], root, num[450000], cnt; priority_queue<int> q1; priority_queue<int, vector<int>, greater<int> > q2; inline void update(int x) { if (!q2.size() || x > q2.top()) q2....
#include <bits/stdc++.h> const long long maxn = 200000 + 10; class BIT { private: long long n; long long bit[maxn]; public: BIT(long long size) { n = size; std::fill(bit, bit + maxn, 0); } void add(long long x, long long v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200000 + 10; long long BIT1[MAXN], BIT2[MAXN]; long long N; void update(long long p, long long num, long long *BIT) { for (; p <= N; p += p & -p) { BIT[p] += num; } } long long query(long long p, long long *BIT) { long long sum = 0; for (;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; long long sum1[MAXN], sum2[MAXN], a[MAXN], pos[MAXN]; void add1(long long x, long long y) { if (!x) return; for (; x < MAXN; x += x & -x) { sum1[x] += y; } } long long query1(long long x) { long long ans = 0; for (; x; x -= x & -x) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double Pi = acos(-1); long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } double dpow(double a, l...
#include <bits/stdc++.h> using namespace std; int s[200005], sum[200005], ara[200005], p[200005], seg[4 * 200005]; void add(int x, int n) { while (x <= n) { sum[x]++; x += (x & -x); } return; } int query(int x) { int ret = 0; while (x) { ret += sum[x]; x -= (x & -x); } return ret; } void u...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, sum[maxn], r[maxn]; void add(int i) { while (i <= n) { sum[i]++; i += i & (-i); } } int getsum(int i) { int ans = 0; while (i) { ans += sum[i]; i -= i & (-i); } return ans; } int bs(int s, int e, int t) { int mi...
#include <bits/stdc++.h> using namespace std; using ll = long long; using dd = double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vdd = vector<dd>; using vpll = vector<pll>; using vtll = vector<tll>; using vvll = vector<vll>; using vvdd = vector<vdd>; using vvpll = vector<vpl...
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 5, MXX = 23; const long long mod = 1e9 + 7, inf = 1e18 + 6; int n, a[MX], ind[MX], ver[MX]; void add(int l) { for (int i = l + 1; i < MX; i += i & -i) ver[i]++; } int ask(int pn) { int ans = 0; for (pn++; pn; pn -= pn & -pn) ans += ver[pn]; retu...
#include <bits/stdc++.h> int size = 256 * 1024; int Count(std::vector<int>& tree, int l, int r) { l += size; r += size; int ans = 0; while (l <= r) { if (l % 2) { ans += tree[l]; ++l; } if (r % 2 == 0) { ans += tree[r]; --r; } if (l > r) break; r >>= 1; l >>= ...
#include <bits/stdc++.h> using namespace std; const long long N = 200010; long long tr1[N], tr2[N]; long long n; long long c[N]; long long lowbit(long long x) { return x & -x; } void ud(long long tr[], long long x, long long d) { for (long long i = x; i <= n; i += lowbit(i)) { tr[i] += d; } } long long qur(long...
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; int n, m; int cas, tol, T; set<int> st; int a[maxn], p[maxn]; lo...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double Pi = acos(-1); long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } double dpow(double a, l...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int n, k; char s[maxn]; int pre[maxn << 1], sz[maxn << 1]; vector<int> op[maxn]; int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } void merge(int x, int y) { int fx = find(x), fy = find(y); if (fy == 0) swap(fx, fy); if (fx...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; const int INF = 1e7; char s[maxn]; int fa[maxn], siz[maxn]; int l[maxn][2]; int n, k; int findset(int x) { if (fa[x] == x) return x; return fa[x] = findset(fa[x]); } void Union(int x, int y) { int rx = findset(x), ry = findset(y); if (!ry) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10, inf = 0x3f3f3f3f; vector<int> v[maxn]; int fa[maxn]; long long cnt[maxn]; int n, k; string s; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void merge(int u, int v) { u = find(u), v = find(v); if (u == v) return; cnt[u] +=...
#include <bits/stdc++.h> using namespace std; const int maxm = 3e5 + 5; int fa[maxm << 1], cnt[maxm << 1], n, k, state[maxm][2]; int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); } void Union(int x, int y) { x = Find(x), y = Find(y); if (y == 0) swap(x, y); fa[y] = x; if (x) cnt[x] += cnt[y]; } int...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6 + 100; const int mod = (int)1e9 + 7; int n, k, fa[maxn], tot[maxn], ans; char s[maxn]; vector<int> v[maxn]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void join(int x, int y) { x = find(x); y = find(y); if (x != y) fa[x]...
#include <bits/stdc++.h> int a[300005]; std::vector<int> g[300005]; int vis[600005], count[600005]; int p[600005]; int find(int u) { if (p[u] == u) return u; else return p[u] = find(p[u]); } void merge(int u, int v) { int x = find(u), y = find(v); if (x != y) { if (x > y) { p[y] = x; cou...
#include <bits/stdc++.h> using namespace std; long long sz[3000009], par[3000009]; long long res; long long n, k; std::vector<long long> pos[3000009]; long long getparent(long long x) { if (par[x] == x) return x; return par[x] = getparent(par[x]); } void merge(long long x, long long y) { long long p1 = getparent(...
#include <bits/stdc++.h> using namespace std; const long long MAX = 3e5 + 5; long long inf = (long long)30000; long long mod = (long long)998244353; long long ans = 0, vert; long long n, k, par[MAX], sz[MAX], cnt[MAX][2], clr[MAX], pos[MAX]; vector<long long> sets[MAX]; vector<long long> b[MAX]; void x_or(long long dad...
#include <bits/stdc++.h> using namespace std; struct perem { long long t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 1000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.ti...
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 100; vector<int> v[N]; int father[N], cnt[N], k; int Find(int x) { return father[x] = father[x] == x ? x : Find(father[x]); } void unite(int x, int y) { int tx = Find(x); int ty = Find(y); if (tx == ty) return; father[tx] = ty; cnt[ty] += cnt[t...
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 10000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5; const int oo = 1e7 + 5; int du[] = {-1, 0, 0, 1}; int dv[] = {0, -1, 1, 0}; const long long mod = 1e9 + 7; long long sqr(long long x) { return x * x; } int getbit(int state, int i) { return ((state >> i) & 1); } int n, m, res, dad[N + 5]; vector<int> g[N ...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 10; const int apsz = 26; const int INF = 10000007; const unsigned long long mod = 97; const int maxm = 10000 + 10; int n, k; char s[maxn]; int st[maxn]; vector<int> epos[maxn]; int cnt[maxn << 1]; int fa[maxn << 1]; int fd(int x) { return x == fa[x...
#include <bits/stdc++.h> using namespace std; const int MAXN = 600005, INF = 1000000000; int N, K, a[MAXN]; vector<int> V[MAXN]; char S[MAXN]; int fa[MAXN], val[MAXN], ans; int get(int x) { if (fa[x] != x) fa[x] = get(fa[x]); return fa[x]; } void merge(int x, int y) { x = get(x), y = get(y); if (x != y) fa[x] =...
#include <bits/stdc++.h> using namespace std; vector<int> vec[300005]; int par[300005], sz[300005], bit[300005], sister[300005], ans; int find(int node) { if (par[node] == node) return node; par[node] = par[par[node]]; return find(par[node]); } int Union(int a, int b) { if (!b) return a; if (sz[a] < sz[b]) sw...
#include <bits/stdc++.h> using namespace std; int n, K, p[301000], tot, UF[301000], UP[301000], C[301000][2], T[301000]; char s[301000]; vector<int> g[301000], u[301000]; int Find(int a) { int x = a, s = 0; while (x != UF[x]) { s ^= UP[x]; x = UF[x]; } int t = 0, root = x; x = a; while (x != UF[x]) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const int inf = 1e9; int d[maxn], fa[maxn]; int n, k; char s[maxn]; vector<int> vec[maxn]; int get(int x) { if (x == fa[x]) return x; return fa[x] = get(fa[x]); } void merge(int x, int y) { int fx = get(x), fy = get(y); if (fx != fy) { ...
#include <bits/stdc++.h> using namespace std; struct perem { long long t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 1000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.ti...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, k, s, x, op[N][2]; char ch[N]; int p[N << 1], val[N << 1]; int find(int u) { return p[u] == u ? p[u] : p[u] = find(p[u]); } void merge(int a, int b) { if (a == b) return; val[b] += val[a]; p[a] = b; } int main() { scanf("%d%d...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-10; const int MOD = 998857459; const int INF = 0x3f3f3f3f; const int maxn = 3e5 + 10; const int maxm = 5e6 + 10; int n, k, op[maxn][2], p[maxn << 1], val[maxn << 1]; char str[maxn]; int find(int first) { return p[first] ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; long long fac[1] = {1}, inv[1] = {1}; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long mp(long long a, long long b) { long long ret = 1; while (...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int lim = 1000 * 1000 + 5; int nbElem, nbSub; vector<int> subset[lim]; int side[lim]; int isIn[lim][2]; string ini; int rep = 0; int drepr[lim]; int dsz[lim]; int cnt[lim][2]; int dfind(int x) { if (drepr[x] != x) drepr[x] = dfind(drepr[x...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int MAXN = N; const int mx = 5e5; const int inf = 1e9; int arr[MAXN]; vector<int> v1[MAXN]; struct DSU { int tot = 0; int par[MAXN]; int cost[MAXN]; void init() { for (int i = 0; i < N; i++) { par[i] = i; cost[i] = (i % 2...
#include <bits/stdc++.h> using namespace std; struct UF { vector<int> e; UF(int n) : e(n, -1) {} int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); } bool join(int a, int b) { a = find(a), b = find(b); if (a == b) return false; if (e[a] > e[b]) swap(a, b); e[a] += e[b]; e[b] = a; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { x = 0; int fl = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fl = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } x ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 6e5 + 5; int n, K; char S[MAXN >> 1]; vector<int> A[MAXN]; namespace DSU { int fa[MAXN], size[MAXN]; inline void init() { for (int i = 1; i <= K; ++i) fa[i] = i, fa[i + K] = i + K, size[i + K] = 1; } int findfa(int u) { return fa[u] == u ? u : fa[u] = fin...
#include <bits/stdc++.h> using namespace std; int n, k; char s[300005]; vector<int> bel[300005]; int fa[300005 * 2], val[300005 * 2]; int getfa(int now) { return fa[now] == now ? now : fa[now] = getfa(fa[now]); } int getans(int now) { int now2; if (now <= k) now2 = k + now; else now2 = now - k; int xx =...
#include <bits/stdc++.h> using namespace std; int INF = 1000000007; string s; int n, k, c, v, ans; int fat[1000100], siz[1000100]; vector<int> edge[1000100]; struct node { int l, r, xo; node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {} int get() { return min(l, r); } void operator+=(node th) ...
#include <bits/stdc++.h> using namespace std; char op[300005]; int n, k, fa[300005], v[300005], num[300005], sz[300005], ans, gx[300005]; vector<int> vec[300005]; int ff(int x) { if (fa[x] == x) return x; int f = ff(fa[x]); v[x] ^= v[fa[x]]; return fa[x] = f; } inline void merge(int x, int y, int p) { if (ff(...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int n, k, fa[maxn], f[maxn][2], val[maxn], pos[maxn][2], ans; char s[maxn]; int getfa(int x) { if (fa[x] == x) return x; int F = fa[x]; fa[x] = getfa(F); val[x] ^= val[F]; return fa[x]; } void merge(int x, int y, int z) { getfa(x), getfa...
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, cc = 1000000, kl; vector<int> vv; string s; vector<vector<int>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0);...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10; int n, k, l[maxn][2]; int fa[maxn], sz[maxn]; string s; int get_fa(int x) { if (x == fa[x]) return x; return fa[x] = get_fa(fa[x]); } int calc(int x) { int y = x <= k ? x + k : x - k; x = get_fa(x), y = get_fa(y); if (x == 0 || y == 0) r...
#include <bits/stdc++.h> using namespace std; int n, m; int fa[300005]; int x[300005], y[300005]; int f[300005][2]; int a[300005][3], b[300005]; int p; char s[300005]; int main() { scanf("%d%d%s", &n, &m, s); for (int i = 1; i <= m; i++) { int ha; scanf("%d", &ha); while (ha--) { int haha; s...
#include <bits/stdc++.h> using namespace std; long long poww(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } const long long MAXN = 1e6 + 10; const long long INF = 8e18; const long long ...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10; int n, k, l[maxn][2]; int fa[maxn], sz[maxn]; string s; int get_fa(int x) { if (x == fa[x]) return x; return fa[x] = get_fa(fa[x]); } int calc(int x) { int y = x <= k ? x + k : x - k; x = get_fa(x), y = get_fa(y); if (x == 0 || y == 0) r...
#include <bits/stdc++.h> using namespace std; int n, m; char s[630000]; int fa[630000]; int val[630000]; vector<int> belong[630000]; int Push(int x) { return x; } int Unpush(int x) { return m + x; } int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } bool vis[630000]; void merge(int x, int y) { int u = f...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long INFLL = 4e18L; const int MOD = 0; const int N = 3e5 + 3; const int BLUE = 1, RED = 2; int n, k; char init_state[N]; vector<int> has[N]; int color[N]; vector<int> adj_same[N], adj_diff[N]; struct DSU { vector<int> _leader, _size, _force...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10; int n, k, l[maxn][2]; int fa[maxn], sz[maxn]; string s; int get_fa(int x) { if (x == fa[x]) return x; return fa[x] = get_fa(fa[x]); } int calc(int x) { int y; if (x <= k) y = x + k; else y = x - k; x = get_fa(x), y = get_fa(y);...
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, cc = 1000000, kl; vector<int> vv; string s; vector<vector<int>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0);...
#include <bits/stdc++.h> using namespace std; const int MAXN = 900000; int papa[MAXN], peso[MAXN], custo[MAXN]; int k; bool obg[MAXN]; int find(int a) { if (papa[a] == -1) return a; return papa[a] = find(papa[a]); } bool juntos(int a, int b) { return find(a) == find(b); } void uni(int a, int b) { a = find(a); b...
#include <bits/stdc++.h> using namespace std; const int N = 6E5 + 10; int n, k, l[N][2]; int fa[N], sc[N]; string s; int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } int cal(int x) { int y = x <= k ? x + k : x - k; int xx = find(x), yy = find(y); if (xx == 0 || yy == 0) return sc[xx +...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MAX_N = 6e5 + 5; int n, k, a[MAX_N >> 1]; vector<int> op[MAX_N >> 1]; int fa[MAX_N], val[MAX_N]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void unit(int x, int y) { int fx = find(x), fy = find(y); if (fx != fy) fa[fy...
#include <bits/stdc++.h> using namespace std; int n, k, pre[300005 * 2]; char s[300005]; inline int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } int val[300005 * 2], tmp, m; vector<int> ve[300005]; int ans; inline int getmin(int x) { return min(val[find(x)], val[find(x + k)]); } inline void merge(int...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
#include <bits/stdc++.h> using namespace std; int n, m, k, x; vector<int> vec[300010]; char c[300010]; int fa[300010 << 1], sz[300010 << 1]; int lim[300010 << 1]; int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } int main() { scanf("%d%d%s", &n, &k, c + 1); for (int i = 1; i <= k; i++) {...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 7; int n, k; string s; int l[maxn][2], r[maxn], cnt[maxn]; int getroot(int x) { return r[x] == x ? x : r[x] = getroot(r[x]); } int calc(int x) { int y = x + k; x = getroot(x); y = getroot(y); if (x == 0 || y == 0) { return cnt[x + y]; } ...
#include <bits/stdc++.h> using namespace std; long long inf = 1000000; const int N = 300000; vector<int> tree(2 * N + 4); vector<int> ranks(2 * N + 4, 0); char str[N + 4]; int find(int x) { return x == tree[x] ? x : tree[x] = find(tree[x]); } void link(int x, int y) { if (ranks[x] > ranks[y]) { tree[y] = x; } e...
#include <bits/stdc++.h> using namespace std; long long ans = 0; long long val[600010]; int have[600010][2], fa[600010]; char str[600010]; int n, k; int find(int x) { return x == fa[x] ? x : (fa[x] = find(fa[x])); } int other(int u) { return u <= k ? u + k : u - k; } void update(int u, long long x, long long y) { ans...
#include <bits/stdc++.h> using namespace std; inline int read() { int w = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { w = (w << 3) + (w << 1) + ch - 48; ch = getchar(); } return w * f; } int n, m, f...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, k, s, x, op[N][2]; char ch[N]; int p[N << 1], val[N << 1]; int find(int u) { return p[u] == u ? p[u] : p[u] = find(p[u]); } void uni(int a, int b) { if (a == b) return; val[b] += val[a]; p[a] = b; } int main() { scanf("%d%d%s...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 7; using ll = long long; string s; int n, k; int fa[maxn]; vector<int> st[maxn]; const int inf = 0x3f3f3f3f; ll sz[maxn]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void Union(int x, int y) { x = find(x), y = find(y); if (x !...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int dp[maxn][2], fa[maxn * 2], cnt[maxn * 2], n, k; char buf[maxn]; int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } int calc(int x) { int y = (x <= k ? x + k : x - k); x = Find(x), y = Find(y); if (x == 0 || y == 0) return cnt...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 5; const int N = 600010; class DSU { public: int p[N], cost[N]; int n; int ans = 0; DSU(int _n) : n(_n) { for (int i = 0; i < n; i++) { cost[2 * i + 1] = 1; cost[2 * i] = 0; } cost[2 * n] = inf; cost[2 * n + 1]...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10; int f[maxn], n, k, w[maxn]; vector<int> v[maxn]; int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); } int ask(int x) { int y = (x <= k) ? x + k : x - k; x = Find(x); y = Find(y); if (x == 0) return w[y]; else if (y == 0) ...
#include <bits/stdc++.h> using namespace std; struct DS { int rank, cost, parent; bool forced; } ds[4 * 300100]; int ans; char status[300100]; vector<int> subs[300100]; int neg(int n) { return n + 300100; } int find(int n) { if (n == ds[n].parent) return n; return ds[n].parent = find(ds[n].parent); } void join(...
#include <bits/stdc++.h> using namespace std; const long long llINF = 2e18, llMOD = 1e9 + 7; const int INF = 2e9, MOD = 1e9 + 7, P = 179, N = 2e3 + 1, K = 23000, L = 18; const long double EPS = 1e-6, ldINF = 1e18, PI = acos(-1); template <typename T> inline void sort_uniq(vector<T>& v) { sort(v.begin(), v.end()); v...
#include <bits/stdc++.h> using namespace std; const long long MX = 1e6, INF = 1e9 + 10; vector<long long> v[MX]; long long par[MX], s0[MX], s1[MX], col[MX], ans = 0; pair<long long, long long> GETPAR(long long v) { if (par[v] == v) return {v, 0}; pair<long long, long long> ans = GETPAR(par[v]); return {par[v] = a...
#include <bits/stdc++.h> using namespace std; int test = 0; const int MAXN = 300009; const long long MOD = 119 << 23 | 1; class { public: vector<int> V[MAXN]; int fa[MAXN * 2], cnt[MAXN * 2]; int n, m; int findfa(int x) { if (fa[x] == x) return x; return fa[x] = findfa(fa[x]); } void merge(int x, i...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-10; const int MOD = 998857459; const int INF = 0x3f3f3f3f; const int maxn = 3e5 + 10; const int maxm = 5e6 + 10; int n, k, op[maxn][2], p[maxn << 2]; long long val[maxn << 2]; char str[maxn]; int find(int first) { return...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 7; class DSU { private: vector<int> comp, siz; vector<int> tp; vector<int> onc, offc; public: DSU(int n) : comp(n), siz(n, 1), tp(n, 0), onc(n, 0), offc(n, 1) { for (int i = 0; i < n; ++i) comp[i] = i; offc[n - 1] = INF; } p...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool umax(T& a, const T& b) { return a < b ? a = b, true : false; } template <long long sz> using tut = array<long long, sz>; const long long N = 3e5 + 5; const lon...