HDU 2795 Billboard. (line segment tree)
Question connection: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 2795
~~~~
Start to learn about the data structure. Let's start with a simple process. If you get tired of questions, write a problem-solving report. Haha, boiling, Segment tree!
~~~~
A h * w billboard, after which n 1 * wi-sized advertisements are pasted on the billboard in turn, and always pasted to the top left corner, q: What is the height after all advertisements are posted?
# Include
# Include # define lson rt <1, s, mid # define rson rt <1 | 1, mid + 1, eusing namespace std; const int maxn = 222222; int tre [maxn <2]; int h, w, n; void pushup (int rt) {tre [rt] = max (tre [rt <1], tre [rt <1 | 1]);} void build (int rt, int s, int e) {tre [rt] = w; if (s = e) return; int mid = (s + e)> 1; build (lson); build (rson);} int query (int rt, int s, int e, int x) {if (s = e) {tre [rt]-= x; return s;} int mid = (s + e)> 1; int ans = (tre [rt <1 ]> = X )? Query (lson, x): query (rson, x); pushup (rt); // write the update operation directly to the query function. Return ans;} int main () {while (scanf ("% d", & h, & w, & n) = 3) {if (h> n) h = n; // h> n, the extra space will be wasted, and RE build (, h) will appear ); while (n --) {int q; scanf ("% d", & q); if (tre [1]