%%% Lee Ultra
Due to Watch J oe Great God decadent study found that high-level data structures
Attracted to the disaster (my first change did not change completely finished T2 T1
Instructions:
Purpose: to maintain the optimal time Functions
Complexity: $ \ Theta (n log_ {2} n ^ {2}) $
Food Guide:
We first segment tree node information stored in memory instead of a line
The segments are stored are not necessarily the most at each point range, but should be the best in the interval
There is no feeling like a two-dimensional MLE segment tree
Of course there can be so different in the two lines are the best locations in the same range
At this excellent maintenance interval longer
(On the assumption that the maximum maintenance
Interval Review:
We consider two line segments
First, we want the segment positioned line segment tree, then there will be $ log_ {2} n $ intervals need to be modified
Next, we only consider a range of Kazakhstan
By the relative position of the two segments was strong Category talk:
A total of four cases
1.
Line $ a $ (blue) than the current slope of the best line $ b $ (perhaps orange) small
And the right side of the midpoint of the intersection of two segments
Then obviously the interval for the current interval and the left line $ a $ better,
Here it can recursively to stop (current section has been modified and then modify the left side of the interval to be meaningless
But for the right side of the interval
$ B $ segments may still be better
At this time, the segment should be $ b $ recursive parameter modification right section
2.
$ A $ line (supra) the slope of the line segment is smaller than the current optimal $ B $ (supra)
And the intersection of two line segments in the left midpoint
$ A $ line interval in left only possible better
At this time, the segment should be $ A $ recursive parameter modification left section
3.
Line $ a $ (ibid.) Slope is greater than the current optimal line $ b $ (ibid)
And the right side of the midpoint of the intersection of two segments
$ A $ line section on the right side only may more preferably
At this time, the segment should be $ A $ recursive parameter modification right section
4.
Line $ a $ (ibid.) Slope is greater than the current optimal line $ b $ (ibid)
And the intersection of two line segments in the left midpoint
For the current section and the left section line $ b $ better,
At this time, the segment should be $ b $ recursive parameter modification left section
A single point of inquiry:
Queries can be normal
Note should be taken at the minimum and maximum values for each node
Because the optimal solution and may come from a leaf node
It is also possible from the ancestor node
Attached The examination T1 Code:
#include<bits/stdc++.h>
using namespace std; #define int long long #define cin(k) scanf("%lld",&k) #define l(k) ((k)<<1) #define r(k) (l(k)|1) const int maxn=64646,base=32323; struct line{int k,b;}; struct Tree{ struct tree{ int bo; line li; }t[base<<3]; bool cmp(int p,line x,line y) { p-=base; return x.k*p+x.b>=y.k*p+y.b; } void add(int k,int l,int r,line li) { if(l==r) { if(cmp(l,li,t[k].li)) t[k].li=li; return; } int mid=(l+r)>>1; if(t[k].li.k<=li.k) { if(cmp(mid,li,t[k].li)) { add(l(k),l,mid,t[k].li); t[k].li=li; } else add(r(k),mid+1,r,li); } else { if(cmp(mid,li,t[k].li)) { add(r(k),mid+1,r