#include using namespace std; using ll = long long; using V = vector; using VV = vector; using VVV = vector; using VS = vector; using VB = vector; using VVB = vector; using P = pair; using VP = vector

; using M = map; using Q = queue; using PQ = priority_queue; using PQG = priority_queue>; using S = set; const ll MOD = 1000000007; const ll mod = 998244353; const ll INF = 1LL << 60; #define rep(i,n) for(ll i = 0; i < n; i++) #define rep2(i,s,n) for(ll i = s; i < n; i++) #define per(i,n) for(ll i = n; i >= 0; i--) #define per2(i,s,n) for(ll i = n; i >= s; i--) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define fi first #define se second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define eb emplace_back #define lb lower_bound #define ub upper_bound templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(avoid Vin(vector&a){rep(i,(ll)a.size())cin>>a[i];} templatevoid VVin(vector>&a){rep(i,(ll)a.size())rep(j,(ll)a[i].size())cin>>a[i][j];} templatevoid Vout(const vector&a){rep(i,(int)a.size())cout<0){if(b&1)res=res*a%M;a=a*a%M;b>>=1;}return res;} const ll H[4] = {0,1,0,-1}, W[4] = {1,0,-1,0}; struct LCA { VV par; V dis; LCA() {} LCA(const VV &G, ll root = 0) { ll v = G.size(), k = 0; while(v) { v >>= 1; k++; par.assign(k,V(v,-1)); dfs(G, root, -1, 0); rep(i,k-1) rep(j,v) { if(par[i][j] < 0) par[i+1][j] = -1; else par[i+1][j] = par[i][par[i][j]]; } } } void dfs(const VV &G, ll v, ll p, ll d) { par[0][v] = p; dis[v] = d; for(ll nv : G[v]) if(nv != p) dfs(G, nv, v, d+1); } ll lca(ll u, ll v) { if(dis[u] < dis[v]) swap(u,v); ll k = par.size(); rep(i,k) if(dis[u]-dis[v] & 1< par, rank; UnionFind() {} UnionFind(long long n) : par(n), rank(n) { for(long long i = 0; i < n; i++) par[i] = i, rank[i] = 0; } long long root(long long v) { return par[v] == v ? v : par[v] = root(par[v]); } bool unite(long long sv, long long tv) { sv = root(sv); tv = root(tv); if(sv == tv) return 0; if(rank[sv] > rank[tv]) swap(sv,tv); par[sv] = tv; if(rank[sv] == rank[tv]) rank[tv]++; return 1; } bool same(long long sv, long long tv) { return root(sv) == root(tv); } }; void f(VV &G, string &s, ll &cnt, ll &v, UnionFind &uf) { ll now = v; while(s[cnt++] == '(') { uf.unite(now,++v); G[now].pb(v); G[v].pb(now); f(G, s, cnt, v, uf); } } int main() { ll n, q; string s; cin >> n >> q >> s; UnionFind uf(n/2); VV G(n/2); ll cnt = 0, v = 0; while(cnt < n) f(G, s, ++cnt, v, uf); LCA l(G); }