prompt
string
response
string
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") #pragma GCC optimize("O2") template <class T> inline void RD(T &); template <class T> inline void OT(const T &); inline int RD() { int x; RD(x); return x; } template <class T> inline T &_RD(T &x) { RD(x); return x; } inli...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[1000010]; scanf("%s", ch); return ch; } const int MAX_LG = 21; const int maxn = 2e5 + 100; const int base = 29; const int mod = 1e9 + 7; const int INF = 2e9 + 100; vector<int...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 100007; const int MAXL = 21; const int MAXS = MAXN * 4; const int MAX = 131072; int n, m; class hldT { public: ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; inline int read() { int res = 0; int neg; while (true) { char ch = getchar(); if (ch >= '0' && ch <= '9' || ch == '-') { if (ch == '-') neg = -1; else neg = 1, res = ch - '0'; break; } } while (true) { char ch = ge...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MAXN = 110000; int n, m; vector<int> e[MAXN]; int p[MAXN], sz[MAXN], nxt[MAXN], hvp[MAXN], q[MAXN]; int incy[MAXN], pos[MAXN]; int stc; vector<int> cycle; struct sNode { int a, b; int d, mark; int lc, rc; }; int tl; sNode t[MAXN * 6]; int Create(int a, int b...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; struct BIT { int v[131072 * 2], V[131072 * 2]; void init() { memset(v, 0, sizeof(v)); memset(V, 0, sizeof(v)); } void upd(int p, int s, int e, int i, int j) { if (i <= s && e <= j) { v[p] = 1 - v[p]; V[p] = (e - s + 1) - V[p]; } else { ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100050; int inc[MaxN], vst[MaxN], n, in[MaxN], ax[MaxN], N, st[MaxN], ST; int pos[MaxN], Fa[MaxN], m, tot; struct Edge { int v; Edge *nxt; } buf[MaxN * 2], *g[MaxN], *pt; void add(int u, int v) { pt->v = v; pt->nxt = g[u]; g[u] = pt++; } void dfs(...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e5 + 200; const int M = 1e5; const int mod = 0; const int inf = 2e9 + 3; const long long INF = 1e18; const long doub...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9, LG = 17; int N, Q, ret = 0; vector<int> adj[100001], CM; int H[100001], P[100001], jump[100001][LG]; int id[100001], sz[100001], par[100001], root = 0; struct Segtree { int n; vector<int> seg; vector<bool> lz; inline void init(int N) { n = N...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using std::swap; const int maxn = 100000 + 10; const int maxlogn = 17 + 1; int n, m, group; int e_tot, e_l[maxn], e_t[maxn << 1], e_next[maxn << 1], e_x[maxn]; int papa[maxn][maxlogn]; int loop_size, loop[maxn]; bool in_loop[maxn], vis[maxn]; int head, tail, queue[maxn]; int size[maxn], up[maxn...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5; const long long linf = 1e18 + 5; const int N = 1e5 + 5; const int LOG = 17; class node { public: int on, off, lazy; }; int n, m, x, y, cur_tree, something_stupid, all_off, cycle_off; int in[N], next_on_cycle[N], prev_on_cycle[N], order[N]; int wh...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int maxn = 100020; int N, M, is[maxn], tme, seg[4 * maxn][2]; int ata[maxn], lc[20][maxn], der[maxn]; int d[maxn], f[maxn], go[maxn]; bool lazy[4 * maxn][2]; bool used[maxn], heavy[maxn]; vector<pair<int, int> > komsu[maxn]; vector<int> cyc; int findcycle(int node, in...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; const double PI = acos(-1.0); struct vert { vector<int> inc; int h; int ind; int anc; int *D; int *V; int *Add; int n; int cnt; int from; } g[100001]; int Anc[100001]; int N[100001]; int pathCnt; int BuffD[40000...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:65777216") using namespace std; int n, m; int p[111111]; int P(int x) { return p[x] == x ? x : p[x] = P(p[x]); } int ta, tb; vector<pair<int, int> > v[111111]; int lca[111111][20]; int s[111111]; int d[111111]; int dfs(int ver, int par = -1, int depth = 0) { lc...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; int n, m; int k; bool debug = false; const int T = 270000, Log = 17; int tot, cnt, r; int e[200005], nxt[200005], head[200005], v[200005], sta[200005], C[200005], dep[200005], id[200005], fa[200005][17], E[200005], Nxt[200005], H[200005], sz[200005], sum[T], seq[200...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
import java.io.*; import java.util.*; import java.math.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { class SegmentTree { int n; int [] t, flip; public SegmentTree(int n) { this.n = n; t = new int [4 * n]; flip = new int [4 * n]; } ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; ostream cnull(NULL); template <class TH> void _dbg(const char *sdbg, TH h) { cnull << sdbg << "=" << h << "\n"; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cnull << *sdbg++; cnull << "=" << h << ","; _dbg(sdbg...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T qmin(const T a, const T b) { return a < b ? a : b; } template <typename T> inline T qmax(const T a, const T b) { return a > b ? a : b; } template <typename T> inline void getmin(T &a, const T b) { if (a > b) a = b; } template <typename T...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MAXN = (int)1e5 + 7; const int infint = (int)1e9; int n, m, par[MAXN], a, b, visited[MAXN], dp[MAXN], pos[MAXN], ans = 0, st[MAXN], chain[MAXN], tme, sub[MAXN], h[MAXN]; int seg[4 * MAXN], lazy[4 * MAXN]; void upd(int node, int st...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") #pragma GCC optimize("O2") template <class T> inline void RD(T &); template <class T> inline void OT(const T &); inline int RD() { int x; RD(x); return x; } template <class T> inline T &_RD(T &x) { RD(x); return x; } inli...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 1e5 + 113; v...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; int t, T, L, mb, mdb, ans, d[100005], z[100005], g[100005], o[100005], fa[100005], FA[100005], p[100005 * 2], nxt[100005 * 2]; struct LCtree { int g, t, l[100005], r[100005], z[100005], a[100005], x[100005], y[100005], fa[100005], root[100005]; void put(int i,...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; struct segtree { int n; vector<int> tree; vector<int> rev; segtree() {} segtree(int n_) { n = n_; tree.assign(n * 4, 0); rev.assign(n * 4, 0); } void build(int v, int l, int r, vector<int> &a) { if (l + 1 == r) { tree[v] = a[l]; ret...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> #pragma comment(linker, "/stack=64000000") using namespace std; const long double EPS = 1E-5; const int INF = 1E9; const int NMAX = 100500; const int LOG = 20; int n, m, cur_cc; vector<vector<int> > g; vector<int> path, used, cycle, cnt, cc, in_cycle; void dfs(int v, int p) { used[v] = (int)(...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int N = 100005, LG = 17; struct seg { int tg[N * 4], sum[N * 4], t[N * 4]; void pushdown(int k) { if (!tg[k]) return; t[k * 2] = sum[k * 2] - t[k * 2]; t[k * 2 + 1] = sum[k * 2 + 1] - t[k * 2 + 1]; tg[k] ^= 1; tg[k * 2] ^= 1; tg[k * 2 + 1] ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int N = 111111; int n, m; int p[N]; int P(int x) { return p[x] == x ? x : p[x] = P(p[x]); } int ta, tb; vector<pair<int, int> > v[N]; int lca[N][20]; int s[N]; int d[N]; int dfs(int ver, int par = -1, int depth = 0) { lca[ver][0] = par; d[ver] = depth; s[ver] = ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, nq; vector<int> g[N]; vector<int> stk, cycle; bool vis[N], incyc[N]; int fl[N], sz[N], tin[N], tmr, up[N], fa[N]; int seg[8 * N]; bool lazy[8 * N]; int pos[N], startCycle, posInCycle[N]; int onEdges; bool cycleOn; inline void dfsInit(int v, int ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; struct node { node *p, *r, *l; int size, mysize, on; bool flip, edge; int id; node() {} node(int i, int x) { id = i; size = mysize = x; on = x = flip = edge = 0; l = r = p = NULL; } bool is_root() { return !p || (p->l != this && p->r != this)...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; ostream cnull(NULL); template <class TH> void _dbg(const char *sdbg, TH h) { cnull << sdbg << "=" << h << "\n"; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cnull << *sdbg++; cnull << "=" << h << ","; _dbg(sdbg...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; vector<long long int> E[100005]; long long int end_num[100005]; long long int depth[100005]; long long int pr[100005]; long long int num_pr[100005]; long long int COUNT = 1; long long int NUM[100005]; long long int loop_num[100005]; long long int loop_start; long long int l...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; bool heavy[MAXN], cyc[MAXN]; int n, que, nc, use = 1, edge, cnt; int par[MAXN], nex[MAXN], root[MAXN], ind[MAXN], hei[MAXN], mark[MAXN], sz[MAXN]; vector<int> cycle, Q; vector<int> adj[MAXN], child[MAXN]; struct segmentTree { int n; vec...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") #pragma GCC optimize("O2") template <class T> inline void RD(T &); template <class T> inline void OT(const T &); inline int RD() { int x; RD(x); return x; } template <class T> inline T &_RD(T &x) { RD(x); return x; } inli...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:36777216") #pragma GCC optimize("O2") template <class T> inline void RD(T &); template <class T> inline void OT(const T &); inline int RD() { int x; RD(x); return x; } template <class T> inline T &_RD(T &x) { RD(x); return x; } inli...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<int> t[maxn], g[maxn], cycle; int n, N, par[maxn], pos[maxn], h[maxn], st[maxn], sz[maxn], up[maxn], seg[8 * maxn], lazy[8 * maxn], root[maxn]; bool in_cycle[maxn], visited[maxn], isheavy[maxn]; void propagate(int, int, int); int get(in...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9, LG = 17; int N, Q, ret = 0; vector<int> adj[100001], CM; int H[100001], P[100001], jump[100001][LG]; int id[100001], sz[100001], par[100001], root = 0; struct Segtree { int n; vector<int> seg; vector<bool> lz; inline void init(int N) { n = N...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct Edge { int x, y, s; Edge *op; Edge() { s = 0; } Edge(int _x, int _y) { x = _x; y = _y; s = 0; } } null; vector<Edge> adj[N]; Edge *fa[N]; int sub_size[N]; int depth[N]; int Q[N]; int pi[N]; int pj[N]; int total; struct Seg_...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int inf = 1234567890; const int64_t inf64 = 123456789012345678LL; inline void raiseError(const string &text) { cerr << "Error: " << text; exit(42); } class SegTree { private: int n; vector<int> tree; vector<char> lazy; inline void push(int x, int tl, int ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; int seg[4 * maxn], T, sz[maxn], h[maxn], st[maxn], root[maxn], up[maxn], n, par[maxn], dp[maxn]; vector<int> adj[maxn], ch[maxn], C; bool lazy[4 * maxn]; bitset<maxn> mark, c; bool cmp(int a, int b) { return sz[a] > sz[b]; } void relax(int id, ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; bool heavy[MAXN], cyc[MAXN]; int n, que, nc, use = 1, edge, cnt; int par[MAXN], nex[MAXN], root[MAXN], ind[MAXN], hei[MAXN], mark[MAXN], sz[MAXN]; vector<int> cycle, Q; vector<int> adj[MAXN], child[MAXN]; struct segmentTree { int n; vec...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(100005); vector<int> a[MAXN], cycle, d; int n, m, visited[MAXN], par[MAXN], root[MAXN], num[MAXN], numCycle; int nxt[MAXN], h[MAXN], idx[MAXN], removeEdgeTree, removeEdgeCycle; ; bool isCycle[MAXN], hea...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, Q, flg, top[N], dfn[N]; int sz[N], dep[N], fa[N]; int co[N], q[N], vis[N]; vector<int> e[N], E[N]; struct TREE { int s0[N * 4], s1[N * 4], rev[N * 4]; void build(int k, int l, int r) { s0[k] = r - l + 1; s1[k] = 0; if (l == r) re...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> namespace IO { template <typename T> inline void read(T &x) { x = 0; int f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); x *= f; ret...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
import java.util.List; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.ArrayList; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.math.BigInteger; import java.util.Collections; i...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; template <typename G1, typename G2 = G1, typename G3 = G1> struct triple { G1 first; G2 second; G3 T; }; template <class data_structure, bool excl_l = false> struct heavy_light_decomposition { int n; vector<vector<int>> G; vector<int> parent, depth, head, pos, e...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; bool heavy[MAXN], cyc[MAXN]; int n, que, nc, use = 1, edge, cnt; int par[MAXN], nex[MAXN], root[MAXN], ind[MAXN], hei[MAXN], mark[MAXN], sz[MAXN]; vector<int> cycle, Q; vector<int> adj[MAXN], child[MAXN]; struct segmentTree { int n; vec...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC optimize("no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int N = 2e5 + 100, T = 1100, OO = 150, M = 1e9 + 7, P = 6151, SQ = 360, ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int L = 1000000; char LZH[L]; char *SSS, *TTT; inline char gc() { if (SSS == TTT) TTT = (SSS = LZH) + fread(LZH, 1, L, stdin); return *SSS++; } inline int read() { int x = 0; char c = gc(); for (; c < '0' || c > '9'; c = gc()) ; for (; c >= '0' && c <=...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 15; vector<int> cg[N], g[N]; int a[N], b[N], par[N]; int cyclen, cyc[N], sz[N]; int head[N], vert[N], pos[N]; int ptr, posInCycle[N]; bool isInCycle[N]; bool dfscyc(int v, int p) { for (int ind : cg[v]) { int u = a[ind] ^ b[ind] ^ v; if (u == p...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; struct ww { int l, ll, a, cov, s, key, sum, k; } a[400010]; int i, j, k, n, m, s, an, t, F; int g[400010], fa[400010], f[400010], huan[400010], se[400010], id[400010], ans[400010]; vector<int> b[400010]; void Dfs(int x) { if (s) return; int i; g[++*g] = x; f[x...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; class SegmentTree { public: vector<int> b; vector<int> mod; int n; SegmentTree(){}; SegmentTree(int _n) { start(_n); } void start(int _n) { n = _n; b.resize(4 * n); mod.resize(4 * n); for (int i = 0; i < 4 * n; i++) b[i] = 0; build(1, 1, n);...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int N = 214514; int n, m, a, b, t, T, L, mb, mdb, as; int d[N], z[N], g[N], o[N], fa[N], FA[N], p[N * 2], nt[N * 2]; struct d_tr { int g, t, l[N], r[N], z[N], a[N], x[N], y[N], fa[N], ro[N]; void put(int i, int j) { if (i && j) z[i] = !z[i], a[i] = !a[i], swap...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") const int maxn = 1e5 + 12; int n, q, T, m; vector<int> ad[maxn], C; bool ch[maxn], IN_C[maxn]; int h[maxn], hev[maxn], mn[ma...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[1000010]; scanf("%s", ch); return ch; } const int MAX_LG = 21; const int maxn = 2e5 + 100; const int base = 29; const int mod = 1e9 + 7; const int INF = 2e9 + 100; vector<int...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, m, U, V, echk, par[maxn]; vector<int> E[maxn]; int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); } int fa[maxn], sz[maxn], dep[maxn], top[maxn], son[maxn], dfn[maxn], seq[maxn]; void dfs1(int u, int f) { fa[u] = f, sz[u] =...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
import java.io.*; import java.math.*; import java.util.*; public class Round88E { public static class Reader { private final int BUFFER_SIZE = 1 << 12; private int LENGTH = -1; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 101; const long long M = 1e6 + 101; const long long big = 1e16; const long long hsh2 = 1964325029; const long long mod = 1e9 + 7; const long double EPS = 1e-15; const long long block = 1e7; const long long shift = 2e3; long long n, m; vector<long l...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> void noop() {} const int N = 200007; using namespace std; vector<int> e[N]; vector<pair<int, int> > tempos[N]; vector<int> cycle; int vis[N], pai[N], cnt[N], par[N][20], head[N], lev[N]; int U, V; int comp; int seg[4 * N]; char lazy[4 * N]; int dfs(int u, int p = -1) { vis[u] = 1; for (int ...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
import java.io.*; import java.util.*; /* http://www.codeforces.com/contest/117/problem/E */ public class ESubmit { int n, m, q; int[] ss, ff, first, next, qs, qe; /* We use the integer array representation of an undirected graph. The vertices are numbered 0..n-1. There are two versions of each e...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; struct Node { Node *pre, *ch[2]; int size, cnt; bool on, rev; } node[100050]; int n, dsu[100050]; int m, cir[100050], pos[100050]; int root, online; vector<int> g[100050]; int find_dsu(int u) { if (dsu[u] ^ u) dsu[u] = find_dsu(dsu[u]); return dsu[u]; } int dfs(in...
Problem: You are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off. You are also given m queries represented as (v, u) — change the state of all edges on the shortest pat...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; const int MAXM = 2 * MAXN; int n, m; int to[MAXM], nxt[MAXM], head[MAXN], E; struct ST { vector<int> t; vector<int> rev; ST() {} void resize(int sz) { t.resize(sz); rev.resize(sz); } void inverse(int l, int r) { inverse(1, 0, t.s...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int a[100000], order[100000], ans[100000]; int gcd(int a, int b) { int t; while (a > 0) t = b % a, b = a, a = t; return b; } int main() { int i; int n; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); int j; if (n <= 18) { for (i = 1; i < (...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int n; long long a[100000]; pair<long long, int> arr[100000]; long long gcd(long long num1, long long num2) { if (num1 >...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int P[100005], c1, c2, g1[20], g2[20], pos[400], st1, mn, st2, e, n, i, j, k, from[170][1 << 9][1 << 9], p[100005], a[100005], cnt, u1[20], u2[20], is[100005]; inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } void check(int now, int f1, int f2) { if ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> inline int read() { int x = 0, k = 1; char c = getchar(); for (; c < 48 || c > 57; c = getchar()) k ^= (c == '-'); for (; c >= 48 && c <= 57; c = getchar()) x = x * 10 + (c ^ 48); return k ? x : -x; } const int N = 1e5 + 6; int n, a[N], id[N], ans[N]; int gcd(int x, int y) { return y ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native") #pragma GCC optimize(2, 3, "Ofast") using namespace std; namespace MyMinMax { template <typename T> inline T mn(T x, T y) { return x < y ? x : y; } template <typename T> inline T mx(T x, T y) { return...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; pair<int, int> seq[maxn]; int a[maxn], n, d1[10], d2[10], d1_cnt, d2_cnt, ans[maxn]; bool b[maxn], f[200][1 << 9][1 << 9]; bool contain(int a, int b) { return (a & b) == b; } void getAns(int pos, int s1, int s2) { if (!pos) return; int t1 = 0, ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int N; int A[100005], id[100005]; int ans[100005]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) scanf("%d", &A[i]), id[i] = i; int clk0 = clock(); while (clock() - clk0 < CLOCKS_PER_SEC * 0.45) { ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char c; for (c = getchar(); !isdigit(c); c = getchar()) ; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; } const int N = 1e5 + 50, M = 31700; vector<int> p; void seive() { static int a[M]; memset(a, 0, ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; vector<int> fac(int x) { if (x == 1) return {}; vector<int> ret; for (int i = 2; i * i <= x; i++) { if (x % i == 0) { ret.emplace_back(i); while (x % i == 0) x /= i; } } if (x != 1) ret.emplace_back(x); return ret; } const int maxn = 112345; ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; x = flag ? -x : x; } inline void write(int x) { static...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; struct point { int x, num; } w[101000]; int i, n, G[101000], chk[101000]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { srand(time(nullptr)); scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &w[i].x); w[i].num = i; } clock_t...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; bool solve(const vector<int>& a, int x, int y) { int A = a[x], B = a[y]; int E = 0, F = 0; vector<int> p; for (int d = 2; d * d <= max(A, B); d++) if (A % d == 0 || B % d == 0) { while (A % d == 0) { A /= d; E |= 1 << p.size(); } ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { f = ch == '-' ? -f : f; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } int gcd(int a, int b) { ret...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, a[maxn], id[maxn], ans[maxn]; inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); id[i] = i; } clock_t st = clock(); while (clock(...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Test { static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; std::mt19937_64 rng( std::chrono::steady_clock::now().time_since_epoch().count()); template <class T> inline T rnd(T l, T r) { return std::uniform_int_distribution<T>(l, r)(rng); } const int N = 2000005, inf = 2e9; int n, a[N], d[5], dd, o[N]; inline void gcd(const in...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Set; import java.io.IOException; import java.io.InputStreamReader; import java.util.TreeSet; import java.util.ArrayList; import java.util.List; import java.util.Stri...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int const N = 101010; int a[N], id[N], v[N]; inline int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { srand(time(0)); int n; scanf("%d", &n); for (int i = 1; i <= (n); ++i) scanf("%d", &a[i]); int g = 0; for (int...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int N = 100005; int n, a[N], p[N], grp[N]; int main() { clock_t clk = clock(); ios::sync_with_stdio(false); srand(time(0)); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, a[N], P[N], ans[N]; inline int GCD(int x, int y) { if (!y) return x; return GCD(y, x % y); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); P[i] = i; } int time = 90; for (; time--;) { ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Test { static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> int read() { register int x = 0; register char ch = getchar(), f = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = !f; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0'); return f ? x : -x; } struct node { int v, id; } a[100005]; int n, g1, g2, b...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; bitset<200> dp[1 << 9][1 << 9]; void get(int x, vector<int> &sp) { for (int a = 2; a * a <= x; a++) { if (x % a == 0) { while (x % a == 0) x /= a; sp.push_back(a); } } if (x > 1) sp.push_back(x); } int main() { int n; cin >> n; int ar[n]; f...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
import java.io.*; import java.util.*; public class F { FastScanner in; PrintWriter out; class O { int pos; int value; boolean isGood; boolean firstGroup; public O(int pos, int value) { this.pos = pos; this.value = value; } } ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> inline long long read() { long long f = 1, x = 0; 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 f * x; } long long gcd(long long a,...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int n; long long a[100000]; pair<long long, int> arr[100000]; long long gcd(long long num1, long long num2) { if (num1 >...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } const string FILENAME = "input"; const int MAXN = 100228; int n; int a[MAXN]; int pos[MAXN...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Test { static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int n, a[100000 + 5], s[100000 + 5], p[100000 + 5]; class FastIO { private: int T; char c, *A, *B, *C, *E, FI[100000], FO[100000], S[100000]; public: inline FastIO() { A = B = FI, C = FO, E = FO + 100000; } template <typename Ty> inline void read(Ty& x) { x...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } mt19937 rnd(12332); const int MAXN = 1e5 + 7; int ans[MAXN]; pair<int, int> a[MAXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, g, past, v, i; cin >> n; for (int i = 0; i ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } mt19937 rnd(12332); const int MAXN = 1e5 + 7; int ans[MAXN]; pair<int, int> a[MAXN]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, g, past, v, i; cin >> n; for (int i = 0; i ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> int n, a[100001], Div[11], top, choose[11], Top, g[100001][21], loga[100001]; int ind[11][100001]; bool vis[100001]; int gcd(int a, int b) { return (!b) ? a : gcd(b, a % b); } int query(int l, int r) { if (l > r) return 0; int k = loga[r - l + 1]; return gcd(g[l][k], g[r - (1 << k) + 1][k...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> const int MAXN = 1e5 + 10; int n, a[MAXN], id[MAXN], ans[MAXN]; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), id[i] = i; clock_t st = clock(); while (clock() - st < 0.4 * CLOCKS_PER_SEC) { std::...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return (!b ? a : gcd(b, a % b)); } int n, allgcd; vector<pair<int, int> > vec; vector<int> ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; cin >> n; vec.resize(n); ans.resize(n); int g; for (int i = 0; i < n; i++) { ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return (!b ? a : gcd(b, a % b)); } int n, allgcd; vector<pair<int, int> > vec; vector<int> ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; cin >> n; vec.resize(n); ans.resize(n); int g; for (int i = 0; i < n; i++) { ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Test { static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.util.*; public class CF1198F { public static void main(String[] args) throws Exception { boolean local = System.getProperty("ONLINE_JUDGE") == ...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; namespace myrand { mt19937 mt(chrono::system_clock::now().time_since_epoch() / chrono::microseconds(1)); long long Int(long long l, long long r) { return uniform_int_distribution<long long>(l, r)(mt); } } // namespace myrand using namespace myrand; const int N...
Problem: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int N = 1e6 + 5; int G[N][20], A[N], n; int hbit[N]; int P[N]; unordered_map<int, int> C; int query(int l, int r) { if (r < l) return 0; int b = hbit[r - l + 1]; if (r - l + 1 == (1 << b)) return G[l][b]; ...