solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
map<int, int> mapa;
map<pair<int, int>, vector<int>> pos;
vector<int> g[MAXN];
int ptr[MAXN];
int used[MAXN];
void euler(int v, vector<int> &res) {
used[v] = true;
for (; ptr[v] < (int)(g[v]).size();) {
++ptr[v];
int u = g[v][ptr[v] - 1]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, k, tot, x, ans, a[1000000], b[1000000], f[1000000], ed[1000000],
nt[1000000], nm[1000000], ss[1000000];
map<int, int> mp, rw;
bool v[1000000];
int gf(int x) {
if (f[x] == x) return x;
f[x] = gf(f[x]);
return f[x];
}
int main() {
scanf("%d %d", &n, &k);
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int n, lim;
int a[MAXN];
int b[MAXN];
bool isfixed[MAXN];
pair<int, int> o[MAXN];
int no;
int dst[MAXN];
int cyc[MAXN], ncyc;
int par[MAXN], sz[MAXN];
int find(int a) {
if (par[a] == a) ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, s, a[200005], b[200005], c[200005], vis[200005], wa, cir, prn[200005],
to[200005], nex[200005], beg[200005], val[200005], e;
bool acs[200005];
void insert(int x, int y, int z) {
to[++e] = y;
nex[e] = beg[x];
beg[x] = e;
val[e] = z;
}
vector<int> tek[20000... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 20;
int a[maxn], q[maxn], num[maxn], par[maxn];
bool visited[maxn];
vector<int> ind[maxn], cycle[maxn];
int f(int v) { return (par[v] == -1) ? v : par[v] = f(par[v]); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
me... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, S;
int a[N], p[N], q[N];
vector<vector<int>> cir;
int uf[N];
int find(int x) { return (uf[x] == x) ? (x) : (uf[x] = find(uf[x])); }
void adjust() {
for (int i = 1; i <= n; i++) {
uf[i] = i;
}
pair<int, int>* b = new pair<int, int>[(n ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n, limit;
int nxt[N], lab[N], flag[N];
pair<int, int> a[N];
vector<int> ans1, ans2;
vector<vector<int> > ans3;
vector<pair<int, int> > v;
int root(int u) {
if (lab[u] < 0) return u;
return lab[u] = root(lab[u]);
}
void join(int u, int v) {
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2e5 + 3;
const int infint = (int)1e9 + 3;
const long long inf = (long long)1e17;
int n, s, a[MAXN], idx[MAXN], final[MAXN], par[MAXN], visited[MAXN];
set<int> id[MAXN], num[MAXN];
vector<int> cyc[MAXN];
bool cmp(int u, int v) { return a[u] < a[v]; }
in... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
con... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n, m;
int a[N + 1];
vector<int> nums;
void discrete() {
sort(nums.begin(), nums.end());
nums.resize(unique(nums.begin(), nums.end()) - nums.begin());
for (int i = 1; i <= n; i++)
a[i] = lower_bound(nums.begin(), nums.end(), a[i]) - nums.b... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct ln {
int val;
ln* next;
};
vector<pair<int, int> >* nl;
vector<pair<int, int> > ar;
int* roi;
bool* btdt;
ln* fe(ln* ath, int cp) {
ln* sv = NULL;
ln* ov = NULL;
for (int i = roi[cp]; i < nl[cp].size(); i = roi[cp]) {
int np = nl[cp][i].first;
int i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200600;
int n, S;
int a[N];
int b[N];
int xs[N];
int k;
vector<int> g[N];
int m;
vector<int> cycles[N];
int p[N];
bool used[N];
void dfs(int v) {
while (!g[v].empty()) {
int id = g[v].back();
g[v].pop_back();
dfs(a[id]);
cycles[m].push_back(i... | 11 | CPP |
#include <bits/stdc++.h>
using std::lower_bound;
using std::max;
using std::min;
using std::random_shuffle;
using std::reverse;
using std::sort;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
void open(const char *s) {}
int rd() {
int s = 0, c, b = 0;
while (((c = getchar()) < '0' ||... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int a[maxn], b[maxn], nxt[maxn];
pair<int, int> srt[maxn];
map<int, vector<int> > mp;
vector<vector<int> > ans;
int par[maxn], who[maxn];
int fnd(int u) { return par[u] < 0 ? u : par[u] = fnd(par[u]); }
v... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m;
const int N = 2e5 + 5;
int a[N], b[N], p[N], vis[N], cnt, head[N], fa[N], ins[N], ok[N];
vector<int> V, tmp;
struct edg {
int to, nxt, w;
} e[N];
void add(int u, int v, int w) {
cnt++;
e[cnt].to = v;
e[cnt].nxt = head[u];
head[u] = cnt;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[200000];
int nxt[200000];
bool v[200000];
vector<int> cycle;
void dfs(int now) {
v[now] = true;
while (nxt[now] < adj[now].size()) {
nxt[now]++;
dfs(adj[now][nxt[now] - 1].first);
}
cycle.push_back(now);
}
void dfs2(int now) {
v... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 202020;
int N, S, val[MAXN], sorted[MAXN], begin_idx[MAXN], incl[MAXN], c = 0;
map<int, int> compress;
vector<int> adj[MAXN], cycle;
map<pair<int, int>, vector<int>> locs;
void recur(int n) {
;
while (adj[n].size() > 0) {
int nex = adj[n].back();
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 239;
int n, s, a[M], p[M];
pair<int, int> b[M];
int parent[M], r[M];
inline void init() {
for (int i = 0; i < n; i++) {
parent[i] = i;
r[i] = 0;
}
}
inline int find_set(int p) {
if (parent[p] == p) return p;
return (parent[p] = find_set(p... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, a[N], K, sum;
map<int, int> mp;
map<int, vector<int> > g;
vector<vector<int> > ans;
vector<int> vec;
inline void dfs(const int x) {
register int i;
while (!g[x].empty())
i = g[x].back(), g[x].pop_back(), dfs(a[i]), vec.push_back(i);
g... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using cat = long long;
void DFS(int R, vector<vector<int> >& G, vector<bool>& vis, vector<int>& cyc) {
vis[R] = true;
while (!G[R].empty()) {
int v = G[R].back();
G[R].pop_back();
DFS(v, G, vis, cyc);
}
cyc.push_back(R);
}
int main() {
cin.sync_with_st... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> pat[500000];
vector<int> rev[500000];
vector<bool> flag[500000];
int pt[500000];
void adde(int a, int b) {
pat[a].push_back(b);
flag[a].push_back(false);
}
vector<int> euler;
void calceuler(int node) {
for (;;) {
if (pt[node] == pat[node].size()) break... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MN = 200010;
int fa[MN];
void init() {
for (int i = 0; i < MN; i++) fa[i] = i;
}
int find(int u) {
if (fa[u] == u)
return u;
else
return fa[u] = find(fa[u]);
}
void mrg(int u, int v) {
u = find(u);
v = find(v);
if (u == v) return;
fa[v] = u;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[200000], b[200000];
vector<int> pos[200000];
int p[200000], nxt[200000];
int parent[200000];
int find(int n) {
if (parent[n] != n) parent[n] = find(parent[n]);
return parent[n];
}
int visited[200000];
vector<int> cycles[200000];
int main() {
int i;
int n, s;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, K;
map<int, int> Map;
int A[201000], B[201000], w[201000];
vector<int> GG[201000];
int GPV[201000];
int tA[201000];
vector<int> G;
int UF[201000], sss;
int Find(int a) {
if (a == UF[a]) return a;
return UF[a] = Find(UF[a]);
}
void Merge(int a, int b) {
a = Find... | 11 | CPP |
#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 = "RDLU";
long long ln, lk, lm;
void etp(b... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct UF {
int n;
vector<int> par;
UF(int n) : n(n) {
for (int i = 0; i < n; i++) par.push_back(i);
}
int find(int a) {
if (a != par[a]) par[a] = find(par[a]);
return par[a];
}
void join(int a, int b) { par[find(a)] = find(b); }
};
struct V {
ve... | 11 | CPP |
#include <bits/stdc++.h>
const int MAX_N = 200000;
int v[1 + MAX_N], poz[1 + MAX_N], sorted[1 + MAX_N];
bool cmp(int a, int b) { return v[a] < v[b]; }
std::vector<int> src[1 + MAX_N], target[1 + MAX_N];
void normalize(int n) {
std::sort(poz + 1, poz + 1 + n, cmp);
int last = v[poz[1]], j = 1;
for (int i = 1; i <=... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
unordered_map<int, int> mp;
int a[N], b[N], he[N], to[N], ne[N], c;
basic_string<int> w[N];
bool v[N];
void dfs(int x) {
v[x] = 1;
for (int i; i = he[x];) he[x] = ne[i], dfs(to[i]), w[c] += i;
}
int main() {
int t = 0, i, j, k, n, s;
scanf("%d... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const long long int INF = 1e18 + 9LL;
int n, s;
int in[N];
int last[N];
int sorted[N];
set<int> place[N];
set<int> value[N];
int cnt;
map<int, int> M;
int dir[N];
bool vis[N];
vector<int> cur;
void solve(int c) {
if (place[c]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], n, s, b[maxn], num[maxn], len;
int ufs[maxn], meme[maxn];
inline int find(int u) {
if (ufs[u] == u)
return u;
else
return ufs[u] = find(ufs[u]);
}
inline void join(int u, int v, int e) {
u = find(u), v = find(v);
if (u ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long Inf = 1e18;
const int N = 2e5 + 10;
const int mod = 0;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (ch >= '0' && ch ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, s;
int niz[maxn], sol[maxn], saz[maxn];
vector<pair<int, int> > graph[maxn];
bool bio[maxn], bio2[maxn];
vector<int> sa;
vector<vector<int> > al;
vector<int> ac[maxn];
void dfs(int node) {
bio2[node] = true;
while (!graph[node].empty())... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, s, a[200079], p[200079];
vector<pair<int, int> > b(200079);
int rodic[200079], r[200079];
int najdisef(int v) {
if (rodic[v] == v) return v;
rodic[v] = najdisef(rodic[v]);
return rodic[v];
}
void spojset(int i, int j) {
i = najdisef(i);
j = najdisef(j);
i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int b[N], t[N], nt[N], u;
vector<int> ans[N];
int top;
int NT(int x) {
while (nt[x] < t[x + 1] && a[nt[x]] == x) ++nt[x];
return nt[x];
}
void dfs(int x) {
while (NT(x) < t[x + 1]) {
int now = nt[x]++;
dfs(a[now]);
ans[top]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN], sorted[MAXN];
vector<int> moves[MAXN];
vector<int> cyc... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], nxt[200010], cnt, n, s;
void solve(vector<int> &v, int i, int &j) {
while (a[j] == a[i]) j++;
if (j >= n) return;
if (b[j] == a[i]) {
swap(a[i], a[j]);
cnt++;
v.push_back(j++);
solve(v, i, nxt[lower_bound(b, b + n, a[i]) - b])... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename S, typename T>
void xmin(S &a, T const &b) {
if (b < a) a = b;
}
template <typename S, typename T>
void xmax(S &a, T const &b) {
if (b > a) a = b;
}
vector<vector<pair<int, int> > > g;
vector<int> eu;
vector<int> cured;
void rec(... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<doub... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
int arr[MAXN], tmp[MAXN];
vector<int> ve[MAXN];
map<pair<int, int>, vector<int> > mapa;
int ind[MAXN];
vector<int> out[MAXN];
int sol = 0;
vector<int> t1, t2;
vector<int> comp;
map<int, int> aaa;
void tour(int x, int i) {
while (ind[x] < ve[x].siz... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
const int N = 2e5 + 5;
int n, s, cnt, to[N], a[N], b[N], pos[N];
vector<int> all[N];
pair<int, int> p[N];
vo... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
const int NN = 200011;
int a[NN], b[NN], arr[NN];
VI vec[NN], cyc[NN];
int nc;
int dp[NN], vst[NN];
int n, s;
void dfs(int u) {
while (not vec[u].empty()) {
int v = vec[u].back();
vec[u].pop_back();
dfs(a[v]);
cyc[nc].push_back(v);
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN], sorted[MAXN];
vector<int> moves[MAXN];
vector<int> cyc... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 10;
int to[sz], pr[sz], si[sz], cyq = 0;
bool us[sz];
vector<int> cy[sz];
int find_se(int v) {
if (v != pr[v]) pr[v] = find_se(pr[v]);
return pr[v];
}
void merge(int u, int v) {
u = find_se(u), v = find_se(v);
if (u != v) {
if (si[v] > si[u]... | 11 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
const int MAXN = 210000;
int was[MAXN];
int wss[MAXN];
vector<int> st;
vector<vector<int>> vv;
vector<vector<int>> vv2;
int lb[MAXN];
int rb[MAXN];
set<int> ss;
int pl[MAXN], cl[MAXN];
int pos[MAXN];
int n;
void dfs1(int v) {
was[v] = 1;
st.pu... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int N, S;
int A[200020], B[200020];
vector<int> vx;
int pp[200020];
int Find(int x) { return pp[x] == x ? x : pp[x] = Find(pp[x]); }
vector<int> vs[2][200020];
int nxt[200020];
int main() {
scanf("%d%d", &N, &S);
for (int i = 1; i <= N; i++) scanf("%d", A + i);
for (i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, S, a[200010], fa[200010];
inline int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }
inline void merge(int x, int y) {
x = getf(x);
y = getf(y);
if (x != y) fa[x] = y;
}
pair<int, int> p[200010];
class node {
public:
int vl, pos, id;
bool oper... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
int n, s;
int a[maxn], b[maxn];
int idx[maxn];
bool CmpI(int i, int j) { return a[i] < a[j]; }
int p[maxn];
int Find(int x) { return x == p[x] ? x : p[x] = Find(p[x]); }
void Unite(int x, int y) { p[Find(x)] = Find(y); }
int _1[maxn], _2[maxn];
void Pr... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
vector<bool> vis;
vector<pair<long long, long long>> eulerWalk(
vector<vector<pair<long long, long long>>>& gr, vector<long long>& eu,
int src, vector<long long>& D, vector<long long>& its) {
vector<pair<long long, long long>> ret, s = ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], nxt[200010];
bool vis[200010];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, s;
cin >> n >> s;
for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
sort(b + 1, b + n + 1);
vector<int> v;
for (int i = 1; i <= n; i++)
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void ckmax(T& x, T y) {
x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
x = (y < x ? y : x);
}
const int MAXN = 2e5;
int n, lim, a[MAXN + 5], goal[MAXN + 5];
int vals[MAXN + 5], cnt_val;
int need_oper_pos;
vector<... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int dsu[N];
int rang[N];
int pred(int a) {
if (a == dsu[a]) return a;
return dsu[a] = pred(dsu[a]);
}
void unite(int a, int b) {
a = pred(a);
b = pred(b);
if (a != b) {
if (rang[a] < rang[b]) {
swap(a, b);
}
dsu[b] = a;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[200010];
int b[200010];
vector<pair<int, int> > graf[200010];
vector<int> tura;
vector<int> sz;
vector<vector<int> > sol;
vector<vector<int> > rj;
vector<int> r;
int bio[200010];
int siz = 0;
void dfs(int x) {
bio[x] = 1;
while (!graf[x].empty()) {
i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;
mt19937_64 randGen(system_clock().now().time_since_epoch().count());
inline void raiseError(string erro... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int N, S, cnt;
int A[200005], A2[200005];
bool Use[200005];
int P[200005];
map<int, int> X;
int cyc, R[200005], TT[200005];
vector<int> V[200005], Cycle[200005];
void Read() {
scanf("%d%d", &N, &S);
for (int i = 1; i <= N; i++) {
scanf("%d", &A[i]);
A2[i] = A[i]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 25;
int a[N], b[N], c[N], cycsz;
vector<int> g[N], cyc[N];
void dfs(int v) {
while (!g[v].empty()) {
int u = g[v].back();
g[v].pop_back();
dfs(a[u]);
cyc[cycsz].push_back(u);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(N... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int const MAX = 4e5 + 41;
int n, s;
int a[MAX];
int b[MAX];
int c[MAX];
vector<int> e[MAX];
vector<vector<int> > ans;
set<int> poses[MAX];
int cnt;
int u[MAX];
int lp[MAX];
int rp[MAX];
vector<int> getposes(vector<int> st) {
reverse(st.begin(), st.end());
vector<int> re... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, K, a[200100];
map<int, int> mp1;
map<int, vector<int> > mp2;
vector<vector<int> > ans;
vector<int> vec;
void dfs(int x) {
for (int i; !mp2[x].empty(); vec.push_back(i)) {
i = mp2[x].back();
mp2[x].pop_back();
dfs(a[i]);
}
mp2.erase(x);
}
int main() ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, s, a[200020], b[200020], p[200020];
bool cmp(int i, int j) { return a[i] < a[j]; }
int rt[200020];
int findrt(int x) {
if (rt[x] != x) rt[x] = findrt(rt[x]);
return rt[x];
}
int get(int x) { return lower_bound(b + 1, b + n + 1, x) - b; }
map<int, int> S;
int c[20... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 200222, inf = 1000111222;
int n, s, cnt, to[max_n];
int a[max_n], b[max_n], pos[max_n];
vector<int> all[max_n];
void compress() {
pair<int, int> p[max_n];
for (int i = 0; i < n; ++i) {
p[i] = {a[i], i};
}
sort(p, p + n);
int num = 0;
for (i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int Begin[N], Next[N], to[N], e;
void add(int u, int v) { to[++e] = v, Next[e] = Begin[u], Begin[u] = e; }
int n, m, k, c;
int A[N], rk[N], st[N], vis[N];
void DFS(int o) {
vis[o] = true;
for (int& i = Begin[o]; i;) {
int u = to[i];
i = N... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, s, a[N], aa[N], g[N], p[N], i, j;
int gfa(int x) { return g[x] == x ? x : g[x] = gfa(g[x]); }
bool bb[N], vi[N];
set<int> S;
unordered_map<int, int> be, en;
unordered_map<int, vector<int>> mp;
int main() {
ios::sync_with_stdio(0);
cin.tie(0... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
return x * neg;
}
inline int qpow(int x, int e, int _MOD) {
int ans = 1;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' &... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
os << '[';
for (unsi... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (len == 0)
return EOF;
else
return s[it++]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int infinity = (int)1e9 + 42;
const int64_t llInfinity = (int64_t)1e18 + 256;
const int module = (int)1e9 + 7;
const long double eps = 1e-8;
mt19937_64 randGen(system_clock().now().time_since_epoch().count());
inline void raiseError(string erro... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005;
int n, s, ct, tmp_n, ans_ct, a[Maxn], b[Maxn], fa[Maxn], pos[Maxn], ord[Maxn],
bel[Maxn], Pos[Maxn];
vector<int> spec, Ve[Maxn];
bool vis[Maxn];
void dfs(int u) {
if (vis[u]) return;
bel[u] = ct, vis[u] = true, dfs(ord[u]);
}
void dfs2(int u... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct A {
int x, id;
} a[N];
bool cmp(A x, A y) { return x.x < y.x; }
int a0[N], s[N], f[N], pre[N], nxt[N];
int f_f(int x) { return x == f[x] ? x : f[x] = f_f(f[x]); }
bool vv[N];
vector<int> t[N];
int main() {
int n, S;
scanf("%d%d", &n, &S);
... | 11 | CPP |
#include <bits/stdc++.h>
inline int rint() {
int x = 0;
char s = getchar();
for (; s < '0' || '9' < s; s = getchar())
;
for (; '0' <= s && s <= '9'; s = getchar()) x = x * 10 + (s ^ '0');
return x;
}
template <typename Tp>
inline void wint(Tp x) {
if (x < 0) putchar('-'), x = -x;
if (9 < x) wint(x / 1... | 11 | CPP |
#include <bits/stdc++.h>
int n, s, a[200010], b[200010], nums[200010], cnt, fa[200010];
int find(int i) { return fa[i] == i ? i : fa[i] = find(fa[i]); }
bool tag[200010];
struct edge {
int to;
edge* next;
} E[200010], *fir[200010];
std::vector<int> C[200010];
void dfs(int i, int t) {
while (fir[i]) {
edge* e ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 20;
int arr[MAXN], srt[MAXN];
bool bio[MAXN];
vector<pair<int, int>> edges[MAXN];
vector<vector<int>> cyc;
void euler(int i) {
bio[i] = true;
while (!edges[i].empty()) {
auto x = edges[i].back();
edges[i].pop_back();
euler(x.first);
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int A[200005], B[200005], Q[200005];
pair<int, int> P[200005];
vector<int> getcycle(int x) {
int init = x;
vector<int> ret;
do {
ret.push_back(x);
x = Q[x];
} while (x != init);
return ret;
}
int par[200005], pos[200005];
int root(int a) {
if (par[a] == ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long big = 1000000007;
const long long mod = 998244353;
long long n, m, k, T, q;
vector<long long> A, A2;
map<long long, long long> M;
long long d = 0;
long long pek[200001] = {0};
long long deg[200001] = {0};
long long par(long long i) {
long long i2 = i;
wh... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[200010], p[200010], n, s;
pair<int, int> b[200010];
int fa[200010], r[200010];
int get_fa(int x) {
if (fa[x] == 0) return x;
fa[x] = get_fa(fa[x]);
return fa[x];
}
void merge(int x, int y) {
int fx = get_fa(x);
int fy = get_fa(y);
if (fx != fy) fa[fx] = fy... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int M = 0, fst[666666], vb[666666], nxt[666666], vc[666666];
void ad_de(int a, int b, int c) {
++M;
nxt[M] = fst[a];
fst[a] = M;
vb[M] = b;
vc[M] = c;
}
void adde(int a, int b, int c) {
ad_de(a, b, c);
ad_de(b, a, c);
}
map<int, int> vis;
int n, s, a[666666], ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200010], b[200010], x[200010], y[200010], f[200010], r[200010],
c[200010], p, d[200010], q;
map<int, int> h;
inline int fa(int i) { return f[i] == i ? i : f[i] = fa(f[i]); }
inline void unit(int i, int j) {
i = fa(i);
j = fa(j);
if (i != j) f[i] = j;
}... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
char buf[25];
const int maxn = 200010;
struct node {
int w, id;
} c[maxn], d[maxn];
vector<int> v[maxn];
int a[maxn], b[maxn], f[maxn], q[maxn];
bool p[maxn];
int n, m, s, ans;
int read() {
int x = 0, f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if... | 11 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
using namespace std;
void redirectIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int n;
int a[210000];
map<int, vector<int>> numberPositions;
int s;
int sa[210000];
int badPos;
vector<vector<int>> vectors;
bool vis[210000];
int goesTo[210000... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int n = 0;
char c;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
;
for (; c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - 48;
return n;
}
const int maxn = 2e5 + 5;
int i, j, n, s, a[maxn], f[maxn], p[maxn], cnt, sum;
vector<i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
using ll = int64_t;
using Pii = pair<int, int>;
using ull = uint64_t;
using Vi = vector<int>;
void run();
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
run();
return 0;
}
vector<vector<Pii>> G;
vector<... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 520233;
int n, s, a[N], b[N];
int fa[N];
int Find(int x) { return (fa[x] == x) ? x : (fa[x] = Find(fa[x])); }
map<int, int> mp;
bool Merge(int x, int y) {
if (Find(x) != Find(y)) {
fa[Find(x)] = Find(y);
return true;
}
return false;
}
int p[N], c... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int fail() {
printf("-1\n");
return 0;
}
const int MN = 2e5 + 100;
const int MS = MN;
int N, S, a[MN], v[MN], g[MN], V, f;
using i2 = array<int, 2>;
i2 b[MN];
using vi2 = vector<i2>;
vi2 w[MN];
bool u[MN];
using vi = vector<int>;
vi c[MN];
int C;
void dfs(int n, int p =... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 202000;
int n, S, ufs[maxN], Id[maxN], vis[maxN];
pair<int, int> A[maxN];
vector<int> Ring[maxN];
int find(int x);
void dfs(int rcnt, int u);
int main() {
scanf("%d%d", &n, &S);
for (int i = 1; i <= n; i++)
scanf("%d", &A[i].first), A[i].second = uf... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
int id, x;
} a[202020], b[202020];
int n, S, doe, cnt;
int fa[202020], size[202020], r[202020], id[202020];
vector<int> col[202020];
bool br[202020];
bool cmp_id(node u, node w) { return u.id < w.id; }
bool cmp_x(node u, node w) { return u.x < w.x; }
int fin... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
int n, s;
int a[200010], b[200010];
int p[200010];
bool used[200010];
int fth[200010];
vector<vector<int>> cycles;
map<int, vector<int>> v, pos;
int root(int x) { return fth[x] == -1 ? x : fth[x] =... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int p[200005], rk[200005];
vector<int> g[200005];
int m;
int a[200005];
int b[200005];
int uq[200005];
bool used[200005];
vector<int> cycles[200005];
void dfs(int u) {
while (!g[u].empty()) {
int i = g[u].back();
g[u].pop_back();
dfs(a[i]);
cycles[m].push_... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
struct Edge {
int from;
int to;
int to_index;
};
class Graph {
public:
explicit Graph(const int n) : edges_(n) {}
void AddEdge(Edge e) { edges_[e.from].push_back(e); }
vector<vector<int>> FindCycles() {
current_edge_.assign(edge... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int b[N], no[N], n0, n, sum, cnt = 0, to[N], vis[N], ran[N];
vector<int> vec[N];
struct nd {
int id, vl;
} a[N];
struct edge {
int to, id;
};
vector<edge> e[N];
bool cmp(nd x, nd y) { return x.vl < y.vl; }
void init() {
int i;
for (i = 1; i <= ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * F;
}
int n, cnt, s, F, tmp;
int ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &x, T y) {
return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
return x > y ? x = y, true : false;
}
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
if (a < b) a = b;
}
const int MAXN = 400013;
int N, S, M, ans, n;
int val[MAXN], arr[MAXN], sorted[MAXN];
vector<int> moves[MAXN];
vector<int> cyc... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
map<int, int> MP;
struct node {
int a, b;
inline node() {}
inline node(int a, int b) : a(a), b(b) {}
bool operator<(node x) const { return a < x.a; }
} nod[N];
int a[N], nxt[N], fa[N], rt[N], sz[N], b[N];
int find(int v) { return fa[v] == 0 ? v... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
struct Edge {
int from;
int to;
int to_index;
};
class Graph {
public:
explicit Graph(const int n) : edges_(n) {}
void AddEdge(Edge e) { edges_[e.from].push_back(e); }
vector<vector<int>> FindCycles() {
vector<vector<int>> resul... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
vector<int> circuit;
vector<int> e[MAXN];
void calc(int v) {
stack<int> s;
while (true) {
if (((int)e[v].size()) == 0) {
circuit.push_back(v);
if (!((int)s.size())) {
break;
}
v = s.top();
s.pop();
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, s, a[200010];
map<int, int> mp1;
map<int, vector<int> > mp2;
vector<vector<int> > ans;
void dfs(int u) {
while (!mp2[u].empty()) {
int i = mp2[u].back();
mp2[u].pop_back();
dfs(a[i]);
ans.back().push_back(i);
}
mp2.erase(u);
}
int main() {
sca... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, S;
int a[N], p[N], q[N];
vector<vector<int>> cir;
int uf[N];
int find(int x) { return (uf[x] == x) ? (x) : (uf[x] = find(uf[x])); }
void adjust() {
for (int i = 1; i <= n; i++) {
uf[i] = i;
}
pair<int, int>* b = new pair<int, int>[(n ... | 11 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.