ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2109. Tourism on Mars

esbybb beware of special cases N=1, x=y [1] // Problem 2109. Tourism on Mars 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);
Segment tree is an overkill. Sparse table does the work easily. Without any corner cases.