|
|
back to boardbeware of special cases N=1, x=y Posted by esbybb 8 Apr 2017 00:33 main { prepare_lca(); if (N!=-1) { build_segement_tree(1,0,N-2); //a[0..n-1] } int Q=read(); while(Q-->0) { int j=x; int x=read()-1; int y=read()-1; if (x!=y) { J= get(1, 0, N-2, x, y-1); } println(j); } } in build_segement_tree .. if (tl==tr) t[v]=lca(tl,tl+1); Re: beware of special cases N=1, x=y Posted by Noob 9 Apr 2017 04:35 Segment tree is an overkill. Sparse table does the work easily. Without any corner cases. |
|
|