Fzu1608 huge mission line segment tree lazy Interval Update + summation

Source: Internet
Author: User

One of the reasons why I woke up today was that the question was really a dog, it's better to look at the case and guess it quickly,

Question: given some intervals, X, Y. The third parameter W is efficiency, which indicates the unit time efficiency during this period. The total efficiency is (Y-x) * w, then some time periods will be repeated. For example, the first time is 1, 4, 1, and the later time is 2, 4, 3. For a period of, the maximum efficiency must be 3 for the range of 2 and 4, which means that when there is a better situation, we will overwrite the previous one.


Of course, there is another reason for this question: When I used to learn the line segment tree, I used to look at the version provided by the senior student. I didn't look at other people's versions at all, as a result, when I did not understand the meaning of the question last night, I found some details wrong in my mind, because others' versions are different from mine, I did one thing last night. This morning, I handled the small details of my mistakes. I have a long head. Really!



# Include <iostream> # include <cstdio> # include <list> # include <algorithm> # include <cstring> # include <string> # include <queue> # include <stack> # include <map> # include <vector> # include <cmath> # include <memory. h> # include <set> # include <cctype> # define ll long # define ll _ int64 # define EPS 1e-8 # define INF 0 xfffffff // const ll INF = 1ll <<61; using namespace STD; // vector <pair <int, int> G; // typedef pair <int, int> P; // vector <pair <int, int>:: iterator ITER; // Map <LL, int> MP; // Map <LL, int>: iterator P; const int n = 50000 + 5; typedef struct node {int L, R; int num ;}; node tree [N * 4]; void build (int l, int R, int ID) {tree [ID]. L = L; tree [ID]. R = r; tree [ID]. num = 0; If (L = r) return; int mid = (L + r)/2; build (L, mid, id <1 ); build (Mid + 1, R, id <1 | 1);} void Pushdown (int id) {If (tree [ID]. num> 0) {tree [ID <1]. num = max (tree [ID]. num, tree [ID <1]. num); tree [ID <1 | 1]. num = max (tree [ID]. num, tree [ID <1 | 1]. num); tree [ID]. num = 0 ;}} void Update (int l, int R, int L, int R, int ID, int Val) {If (tree [ID]. num> = Val) return; // pruning, if (L <= L & R> = r) {If (tree [ID]. num <Val) tree [ID]. num = val; return;} Pushdown (ID); int mid = (L + r)/2; If (L <= mid) Update (L, R, L, mid, ID <1, Val); If (r> mid) Update (L, R, Mid + 1, R, id <1 | 1, Val ); // else {// Update (L, mid, id <1, Val); // Update (Mid + 1, R, id <1 | 1, Val ); //} int query (int l, int R, int ID) {If (L = r) return tree [ID]. num; Pushdown (ID); int mid = (L + r)/2; int ans1 = 0, ans2 = 0; If (L <= mid) ans1 = query (L, mid, id <1); If (r> mid) ans2 = query (Mid + 1, R, id <1 | 1); Return ans1 + ans2 ;} int main () {int n, m; while (scanf ("% d", & N, & M) = 2) {build (1, n, 1); int q = m; int X, Y, W; while (Q --) {scanf ("% d", & X, & Y, & W); Update (x + 1, Y, 1, n, 1, W);} int ans = query (1, n, 1 ); printf ("% d \ n", ANS);} return 0 ;}


# Include <iostream> # include <cstdio> # include <list> # include <algorithm> # include <cstring> # include <string> # include <queue> # include <stack> # include <map> # include <vector> # include <cmath> # include <memory. h> # include <set> # include <cctype> # define ll long # define ll _ int64 # define EPS 1e-8 # define INF 0 xfffffff // const ll INF = 1ll <<61; using namespace STD; // vector <pair <int, int> G; // typedef pair <int, int> P; // vector <pair <int, int>:: iterator ITER; // Map <LL, int> MP; // Map <LL, int>: iterator P; const int n = 50000 + 5; typedef struct node {int L, R; int num ;}; node tree [N * 4]; int ans; void build (int l, int R, int ID) {tree [ID]. L = L; tree [ID]. R = r; tree [ID]. num = 0; If (L = r) return; int mid = (L + r)/2; build (L, mid, id <1 ); build (Mid + 1, R, id <1 | 1);} void Pushdown (int id) {If (tree [ID]. num> 0) {tree [ID <1]. num = max (tree [ID]. num, tree [ID <1]. num); tree [ID <1 | 1]. num = max (tree [ID]. num, tree [ID <1 | 1]. num); tree [ID]. num = 0 ;}} void Update (int l, int R, int ID, int Val) {If (tree [ID]. num> = Val) return; // pruning, if (L <= tree [ID]. L & R> = tree [ID]. r) {If (tree [ID]. num <Val) tree [ID]. num = val; return;}/* Pushdown (ID); */INT mid = (tree [ID]. L + tree [ID]. r)/2; If (r <= mid) Update (L, R, id <1, Val); else if (L> mid) Update (L, R, ID <1 | 1, Val); else {Update (L, mid, id <1, Val); Update (Mid + 1, R, ID <1 | 1, Val) ;}} void query (int l, int R, int ID) {If (L = r) {ans + = tree [ID]. num; return;} Pushdown (ID); int mid = (tree [ID]. L + tree [ID]. r)/2; If (r <= mid) query (L, R, id <1); else if (L> mid) query (L, R, ID <1 | 1); else {query (L, mid, id <1); query (Mid + 1, R, id <1 | 1 );}} int main () {int n, m; while (scanf ("% d", & N, & M) = 2) {build (1, n, 1); int q = m; int X, Y, W; while (Q --) {scanf ("% d", & X, & Y, & W); Update (x + 1, Y, 1, W);} ans = 0; query (1, n, 1); printf ("% d \ n ", ans);} return 0 ;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.