|
|
вернуться в форум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); Segment tree is an overkill. Sparse table does the work easily. Without any corner cases. |
|
|