#ifndef call_from_test #include using namespace std; using Int = long long; #endif //BEGIN CUT HERE class HLD { private: void dfs_sz(int v) { for(int &u:G[v]){ if(u==par[v]) continue; par[u]=v; dep[u]=dep[v]+1; dfs_sz(u); sub[v]+=sub[u]; if(sub[u]>sub[G[v][0]]) swap(u,G[v][0]); } } void dfs_hld(int v,int c,int &pos) { vid[v]=pos++; inv[vid[v]]=v; type[v]=c; for(int u:G[v]){ if(u==par[v]) continue; head[u]=(u==G[v][0]?head[v]:u); dfs_hld(u,c,pos); } } public: vector > G; vector vid, head, sub, par, dep, inv, type; HLD(int n): G(n),vid(n,-1),head(n),sub(n,1), par(n,-1),dep(n,0),inv(n),type(n){} void add_edge(int u,int v) { G[u].emplace_back(v); G[v].emplace_back(u); } void build(vector rs={0}) { int c=0,pos=0; for(int r:rs){ dfs_sz(r); head[r]=r; dfs_hld(r,c++,pos); } } int lca(int u,int v){ while(1){ if(vid[u]>vid[v]) swap(u,v); if(head[u]==head[v]) return u; v=par[head[v]]; } } int distance(int u,int v){ return dep[u]+dep[v]-2*dep[lca(u,v)]; } // for_each(vertex) // [l, r) <- attention!! template void for_each(int u, int v, const F& f) { while(1){ if(vid[u]>vid[v]) swap(u,v); f(max(vid[head[v]],vid[u]),vid[v]+1); if(head[u]!=head[v]) v=par[head[v]]; else break; } } template T for_each(int u,int v,T ti,const Q &q,const F &f){ T l=ti,r=ti; while(1){ if(vid[u]>vid[v]){ swap(u,v); swap(l,r); } l=f(l,q(max(vid[head[v]],vid[u]),vid[v]+1)); if(head[u]!=head[v]) v=par[head[v]]; else break; } return f(l,r); } // for_each(edge) // [l, r) <- attention!! template void for_each_edge(int u, int v,const F& f) { while(1){ if(vid[u]>vid[v]) swap(u,v); if(head[u]!=head[v]){ f(vid[head[v]],vid[v]+1); v=par[head[v]]; }else{ if(u!=v) f(vid[u]+1,vid[v]+1); break; } } } }; //END CUT HERE #ifndef call_from_test #define call_from_test #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct LowLink{ int n,pos; vector ord,low,par,blg,num; vector > G,C,T; vector > > E; vector ap; vector > bs,cand; LowLink(int n):n(n),pos(0),ord(n,-1),low(n), par(n,-1),blg(n,-1),num(n,1),G(n){} void add_edge(int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } bool is_bridge(int u,int v){ if(ord[u]>ord[v]) swap(u,v); return ord[u]=ord[v]){ E.emplace_back(); while(1){ auto e=cand.back(); cand.pop_back(); E.back().emplace_back(e); if(make_pair(min(u,v),max(u,v))==e) break; } } } } void fill_component(int v){ C[blg[v]].emplace_back(v); for(int u:G[v]){ if(~blg[u]||is_bridge(u,v)) continue; blg[u]=blg[v]; fill_component(u); } } void add_component(int v,int &k){ if(~blg[v]) return; blg[v]=k++; C.emplace_back(); fill_component(v); } int build(){ for(int i=0;i cnt(n,0); for(int i=0;i1) ap.emplace_back(i); sort(ap.begin(),ap.end()); ap.erase(unique(ap.begin(),ap.end()),ap.end()); int k=0; for(int i=0;i()); for(auto e:bs){ int u=blg[e.first],v=blg[e.second]; T[u].emplace_back(v); T[v].emplace_back(u); } return k; } }; //END CUT HERE #ifndef call_from_test #define call_from_test #include "../tools/fastio.cpp" #include "../datastructure/unionfindtree.cpp" #include "../mod/mint.cpp" #include "../mod/enumeration.cpp" #undef call_from_test //INSERT ABOVE HERE signed ARC045_D(){ int n; cin>>n; vector xs(2*n+1),ys(2*n+1); for(int i=0;i<2*n+1;i++) cin>>xs[i]>>ys[i]; vector > R(2*n+2),C(2*n+2); for(int i=0;i<2*n+1;i++) R[xs[i]].emplace_back(i); for(int i=0;i<2*n+1;i++) C[ys[i]].emplace_back(i); UnionFind uf(2*n+1); for(auto &v:R) for(auto u:v) uf.unite(v[0],u); for(auto &v:C) for(auto u:v) uf.unite(v[0],u); vector vs; for(int i=0;i<2*n+1;i++){ if(uf.find(i)!=i) continue; if(uf.size(i)&1) vs.emplace_back(i); } assert(!vs.empty()); if(vs.size()>1u){ for(int i=0;i<2*n+1;i++) cout<<"NG\n"; cout<void{ for(auto &v:V){ if(v.empty()) continue; if(!uf.same(vs[0],v[0])) continue; if(v.size()>0u) for(auto u:v) G.add_edge(v[0],u); if(v.size()>1u) for(auto u:v) G.add_edge(v[1],u); } }; add_edge(R); add_edge(C); G.build(); auto ap=G.ap; vector ans(2*n+1,0); for(int i=0;i<2*n+1;i++) if(uf.same(vs[0],i)) ans[i]=1; for(int v:ap){ if(!uf.same(vs[0],v)) continue; for(int u:G.G[v]){ if(G.par[u]!=v) continue; if(~G.par[v]&&G.ord[v]>G.low[u]) continue; if(G.num[u]&1) ans[v]=0; } } for(int i=0;i<2*n+1;i++) cout<<(ans[i]?"OK\n":"NG\n"); cout<>n>>m>>k; using P = pair; map idx; LowLink G(n); for(int i=0;i>a>>b; a--;b--; G.add_edge(a,b); idx[P(a,b)]=idx[P(b,a)]=i; } G.build(); UnionFind uf(m); for(auto vs:G.E) for(auto p:vs) uf.unite(idx[p],idx[vs[0]]); vector> cnt(m); for(auto vs:G.E){ for(auto p:vs){ cnt[uf.find(idx[p])].emplace(p.first); cnt[uf.find(idx[p])].emplace(p.second); } } using M = Mint; using E = Enumeration; E::init(1000); auto calc1= [&](int x)->M{ M res{0}; for(int i=0;i (int)cnt[i].size()) ans*=E::H(k,uf.size(i)); } cout< using namespace std; using Int = long long; #endif //BEGIN CUT HERE template struct SegmentTree{ using F = function; int n; F f; T ti; vector dat; SegmentTree(){}; SegmentTree(F f,T ti):f(f),ti(ti){} void init(int n_){ n=1; while(n &v){ int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } T query(int a,int b){ T vl=ti,vr=ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } template int find(int st,C &check,T &acc,int k,int l,int r){ if(l+1==r){ acc=f(acc,dat[k]); return check(acc)?k-n:-1; } int m=(l+r)>>1; if(m<=st) return find(st,check,acc,(k<<1)|1,m,r); if(st<=l&&!check(f(acc,dat[k]))){ acc=f(acc,dat[k]); return -1; } int vl=find(st,check,acc,(k<<1)|0,l,m); if(~vl) return vl; return find(st,check,acc,(k<<1)|1,m,r); } template int find(int st,C &check){ T acc=ti; return find(st,check,acc,1,0,n); } }; //END CUT HERE #ifndef call_from_test signed ARC038_C(){ int n; scanf("%d",&n); vector cs(n),as(n); for(int i=1;i seg(f,INF); seg.build(vector(n,-1)); vector dp(n); dp[0]=0; seg.set_val(0,0); for(int i=1;i as(n+2,0); for(int i=1;i<=n;i++) scanf("%d",&as[i]); const int INF = 1.1e9; auto f=[](int a,int b){return min(a,b);}; SegmentTree seg(f,INF); seg.build(as); using P = pair; set

sp; for(int k=0;k<2;k++){ for(int i=1;i<=n;i++){ auto check=[&](int x){return x>n>>k; vector as(n); for(int i=0;i>as[i]; auto f=[](ll a,ll b){return a+b;}; SegmentTree seg(f,0); seg.build(as); ll ans=0; auto check=[&](ll d){return d>=k;}; for(int i=0;i rmq([](int a,int b){return max(a,b);},-1); rmq.build(vector(V,-1)); vector > pq(V); map m; int num=0; for(int i=0;i