#define PROBLEM "https://yukicoder.me/problems/4387" #include using namespace std; #define call_from_test #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } //END CUT HERE #ifndef call_from_test signed main(){ return 0; } #endif #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE template struct RangeToRange{ using E = pair; const int n; vector> G; // (0n, 2n) : top segtree (to) // (2n, 4n) : bottom segtree (from) RangeToRange(int n):n(n){ G.resize(n*4); for(int i=1;i [l2, r2) void add_edge(int l1,int r1,int l2,int r2,T c){ int k=G.size(); for(l1+=n,r1+=n;l1>=1,r1>>=1){ if(l1&1) G[2*n+(l1++)].emplace_back(k,0); if(r1&1) G[2*n+(--r1)].emplace_back(k,0); } vector es; for(l2+=n,r2+=n;l2>=1,r2>>=1){ if(l2&1) es.emplace_back(l2++,c); if(r2&1) es.emplace_back(--r2,c); } G.emplace_back(es); } int idx(int v)const{return 1*n+v;} size_t size()const{return G.size();} const vector& operator[](int k)const{return G[k];} }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif #ifndef call_from_test #include using namespace std; #endif //BEGIN CUT HERE struct SCC{ vector< vector > G,R,T,C; vector vs,used,blg; SCC(){} SCC(int n):G(n),R(n),used(n),blg(n){} void add_edge(int u,int v){ G[u].emplace_back(v); R[v].emplace_back(u); } void dfs(int v){ used[v]=1; for(int u:G[v]) if(!used[u]) dfs(u); vs.emplace_back(v); } void rdfs(int v,int k){ used[v]=1; blg[v]=k; C[k].emplace_back(v); for(int u:R[v]) if(!used[u]) rdfs(u,k); } int build(){ int n=G.size(); for(int v=0;v=0;i--){ if(!used[vs[i]]){ T.emplace_back(); C.emplace_back(); rdfs(vs[i],k++); } } for(int v=0;v>n>>a>>b; auto xs=read(n); RangeToRange G(n); for(int i=0;i cnt; for(int i=0;i