solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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) ... | 11 | CPP |
#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] +=... | 11 | CPP |
#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... | 11 | CPP |
#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]... | 11 | CPP |
#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... | 11 | CPP |
#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(... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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);
... | 11 | CPP |
#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 ... | 11 | CPP |
#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... | 11 | CPP |
#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] =... | 11 | CPP |
#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... | 11 | CPP |
#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]) ... | 11 | CPP |
#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) {
... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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] ... | 11 | CPP |
#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)]... | 11 | CPP |
#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 (... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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;
... | 11 | CPP |
#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 ... | 11 | CPP |
#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... | 11 | CPP |
#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 =... | 11 | CPP |
#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) ... | 11 | CPP |
#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(... | 11 | CPP |
#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... | 11 | CPP |
#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);... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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 ... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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);... | 11 | CPP |
#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);... | 11 | CPP |
#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... | 11 | CPP |
#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 +... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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)]... | 11 | CPP |
#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++) {... | 11 | CPP |
#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];
}
... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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 !... | 11 | CPP |
#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... | 11 | CPP |
#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)]... | 11 | CPP |
#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]... | 11 | CPP |
#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)
... | 11 | CPP |
#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(... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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... | 11 | CPP |
#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)]... | 11 | CPP |
#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... | 11 | CPP |
#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 + k : x - k;
x = getroot(x);
y = getroot(y);
if (x == 0 || y == 0) {
return... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
vector<int> g[maxn];
int f[maxn], d[maxn], L[maxn], R[maxn], fix[maxn], gt[maxn], ans = 0;
int n, k;
char str[maxn];
int calc(int x) {
if (fix[x])
return gt[x] ? R[x] : L[x];
else
return min(L[x], R[x]);
}
int find(int x) {
if (f[x] ... | 11 | CPP |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int maxn = 6e5 + 5;
int fa[maxn], val[maxn], ans;
vector<int> V[maxn];
int n, k;
string s;
void init() {
for (int i = 0; i < maxn; ++i) fa[i] = i;
}
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
void merge(int x, int y) {
... | 11 | CPP |
#include <bits/stdc++.h>
enum class LampConstraint { Distinct, Same };
enum class LampSetState { On, Off, PhantomA, PhantomB };
bool isLampSetStateKnown(LampSetState st) {
return st == LampSetState::On || st == LampSetState::Off;
}
typedef struct Edge {
int nodeId;
LampConstraint cons;
Edge(int nodeId_, LampCon... | 11 | CPP |
#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, vvas, cc = 1000000, kl;
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cerr.tie(0);
cin >> n >> k >> s;
vector<vector<int>> la(n, v... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct DS {
int n;
vector<int> s;
vector<int> count;
DS(int n) : n(n), s(n, -1), count(n, 0) {}
int find(int i) { return s[i] < 0 ? i : (s[i] = find(s[i])); }
int counted(int i) { return count[find(i)]; }
void mark(int i, int x) { count[find(i)] += x; }
int ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int MAXN = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
void file() {}
const int N = 3e5 + 5;
int fat[N * 2], Size[N * 2], n, k;
vector<int> vec[N];
int find(int x) { return fat[x] == x ? x : fat[x] ... | 11 | CPP |
#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... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 5;
int pre[N], si[N], num[N / 2], n, m;
bool vis[N];
char s[N];
vector<vector<int> > v(N / 2);
int findd(int x) {
if (pre[x] == x) return x;
pre[x] = findd(pre[x]);
if (vis[x]) vis[pre[x]] = 1;
return pre[x];
}
inline int id(int x) { return x > m... | 11 | CPP |
#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;
if (x <= k)
y = x + k;
else
y = x - k;
x = Find(x), y = Find(y);
if (x ==... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[600005];
int k;
int mx[600005], a[300005], fa[600005];
int find(int x) {
if (fa[x] != x) {
fa[x] = find(fa[x]);
}
return fa[x];
}
void mer(int x, int y) {
int fx = find(x), fy = find(y);
if (fx != fy) {
mx[fx] += mx[fy];
fa[fy] = fx;
}
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 10;
const long long inf = 1e9 + 10;
int f[N], vist[N];
char s[N];
long long val[N];
vector<int> vec[N];
int find(int x) {
if (f[x] == x) return x;
f[x] = find(f[x]);
return f[x];
}
void myunion(int x, int y) {
if (x < y) {
f[y] = x;
val[x... | 11 | CPP |
#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] ? fa[u] = find(fa[u]) : u; }
void uni(int a, int b) {
if (find(a) == find(b)) return;
val[find(b)] += val[find(a)];
fa[find(a)] = find(b... | 11 | CPP |
#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++) {... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int val[300000 + 100], sum[300000 + 100][2], head[300000 + 100];
int f[300000 + 100];
vector<int> V[300000 + 100];
int n, k;
int ans;
int findd(int x) {
if (f[x] == x) return x;
int F = f[x];
f[x] = findd(f[x]);
val[x] = val[x] ^ val[F];
return f[x];
}
char s[3000... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
vector<int> a[300001];
int p[1000001];
long long f[1000001];
const int Max = 6e5;
const int T = 3e5;
int root(int u) {
if (u == p[u]) return u;
return p[u] = root(p[u]);
}
void Merge(int u, int v) {
u = root(u);
v = root(v);
int ru = root(u);
... | 11 | CPP |
#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 +... | 11 | CPP |
#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;
struct rev {
int c0, c1, tag;
void maintain() {
c0 = min(c0, INF);
c1 = min(c1, INF);
}
};
rev info[maxn];
int dsu[maxn... | 11 | CPP |
#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)]... | 11 | CPP |
#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 (a == b) return;
val[b] += val[a];
fa[a] = b;
}
int mix(int a) { retur... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 810000;
int fa[MAXN], val[MAXN], vec[MAXN][3];
int n, k, ans;
char str[MAXN];
int getfa(int x) {
if (fa[x] == x) return x;
return fa[x] = getfa(fa[x]);
}
void merge(int x, int y) {
int p = getfa(x), q = getfa(y);
if (p == q) return;
fa[p] = q;
v... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 69;
int n, k;
string initial;
int dsu[N];
int sz[N];
int szsame[N];
int parity[N];
int restrict[N];
vector<int> belong[N];
int curr = 0;
int getVal(int u) {
if (restrict[u] == 0) return szsame[u];
if (restrict[u] == 1) return (sz[u] - szsame[u]);
r... | 11 | CPP |
#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;
}
inline long long read1(... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long n, k, pa[600010], ct[600010], siz[600010], ans = 0;
vector<long long> g[300010];
string s;
long long find(long long x) {
if (x == pa[x]) return x;
pa[x] = find(pa[x]);
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)3e5 + 10;
int par[maxn << 1], num[maxn << 1];
inline void makeSet(int size) {
for (int i = 1; i <= size; i++) {
par[i] = i;
}
}
inline int find(int x) {
int k, j, r;
r = x;
while (r != par[r]) {
r = par[r];
}
k = x;
while (k != ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, inf = 0x3f3f3f3f;
int n, K, m, x, pos[N][2], ans, fa[N], val[N];
char s[N];
int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }
void add(int x, int y) {
int fx = getfa(x), fy = getfa(y);
if (fx != fy) fa[fx] = fy, val[fy] += val[fx... | 11 | CPP |
#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... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
if (f) x = -x;
return x;
}
template <class t>
inline void wr... | 11 | CPP |
#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] ? fa[u] = find(fa[u]) : u; }
void uni(int a, int b) {
if (find(a) == find(b)) return;
val[find(b)] += val[find(a)];
fa[find(a)] = find(b... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
char s[N];
int par[N], diff[N];
pair<int, int> find(int x) {
if (par[x] == x) return {x, 0};
auto r = find(par[x]);
par[x] = r.first, diff[x] ^= r.second;
return {par[x], diff[x]};
}
int f[N][2], col[N], ans;
int get(int x) {
if (col[x] ... | 11 | CPP |
from sys import stdin
input = stdin.readline
n , k = [int(i) for i in input().split()]
pairs = [i + k for i in range(k)] + [i for i in range(k)]
initial_condition = list(map(lambda x: x == '1',input().strip()))
data = [i for i in range(2*k)]
constrain = [-1] * (2*k)
h = [0] * (2*k)
L = [1] * k + [0] * k
dp1 = [-1 for... | 11 | PYTHON3 |
#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 curset[MAXN * 2], ans;
int findfa(int x) {
if (fa[x] == x) return x;
return fa[x] = findfa(fa[x... | 11 | CPP |
#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);... | 11 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.