Idea: Just consider the destinations on the left departure v u, ie u> v of the situation. A total of tot personal note of departure and destination to satisfy u> v.
The request interval [v, u] and set as to minimize the total distance of the U-turn. The answer is $ m + \ cup_ {i = 1} ^ {tot} [v_i, u_i] $.
May seek union by consolidating interval the way, is about to have a cross section into a new range.
note:
bool cmp(node x,node y){return x.l<y.l||(x.l==y.l&&x.r<y.r);}
sort(b+1,b+1+t2,cmp);
d[t4=1]=b[1];
for(i=2;i<=t2;++i)
{
if (jiao(d[t4],b[i]))
{
d[t4].r=Max(d[t4].r,b[i].r);
d[t4].l=Min(d[t4].l,b[i].l);
}
else d[++t4]=b[i];
}
By the intersection of the above method, i.e., the interval will merge sort order from front to rear, left to right ordering required. Right-to-left sort may arise following:
| A | | four |
| Two | | three |
All of these can be combined into a range, but when scanning, one and two combined, three and four merge, duplicate statistics intersection of two and four.
If you press the right-to-left sort, you need to merge from back to front. "After the front left and right."