Hdu 4107 Gangster (line segment tree. Time Card tight)

Source: Internet
Author: User

Total Submission (s): 2013 Accepted Submission (s): 520


Problem DescriptionThere are two groups of gangsters fighting with each other. the first group stands in a line, but the other group has a magic gun that can shoot a range [a, B], and everyone in that range will take a damage of c points. when a gangster is taking damage, if he has already taken at least P point of damage, then the damage will be doubled. you are required to calculate the damage that each gangster in the first group toke.
To simplify the problem, you are given an array A of length N and a magic number P. Initially, all the elements in this array are 0.
Now, you have to perform a sequence of operation. each operation is represented as (a, B, c), which means: For each A [I] (a <= I <= B), if A [I] <P, then A [I] will be A [I] + c, else A [I] will be A [I] + c * 2.
Compute all the elements in this array when all the operations finish.
InputThe input consists several testcases.
The first line contains three integers n, m, P (1 <= n, m, P <= 200000), denoting the size of the array, the number of operations and the magic number.
Next m lines represent the operations. Each operation consists of three integers a; B and c (1 <= a <= B <= n, 1 <= c <= 20 ).
OutputPrint A [1] to A [n] in one line. All the numbers are separated by a space.
Sample Input

3 2 11 2 12 3 1
 
Sample Output
1 3 1
 
Source2011 Alibaba-Cup Campus Contest
Recommendlcy

# Include <iostream> # include <stdio. h> # include <string. h> using namespace std; const int maxn = 200010; int addv [maxn <2], ma [maxn <2], mi [maxn <2], ans [maxn], pp; // The mi starts to open a small space and actually the TLE pit... Void btree (int L, int R, int k) {int ls, rs, mid; addv [k] = mi [k] = ma [k] = 0; if (L = R) return; ls = k <1; rs = ls | 1; mid = (L + R)> 1; btree (L, mid, ls); btree (mid + 1, R, rs);} void update (int L, int R, int l, int r, int k, int d) {int ls, rs, mid; if (L = l & R = r) {if (mi [k]> = pp) {addv [k] + = 2 * d; mi [k] + = 2 * d; ma [k] + = 2 * d; return;} else if (ma [k] <pp) {addv [k] + = d; mi [k] + = d; ma [k] + = d; return ;}} ls = k <1; rs = ls | 1; mid = (L + R)> 1; if (Addv [k]) {addv [ls] + = addv [k]; addv [rs] + = addv [k]; mi [ls] + = addv [k]; ma [ls] + = addv [k]; mi [rs] + = addv [k]; ma [rs] + = addv [k]; addv [k] = 0;} if (r <= mid) update (L, mid, l, r, ls, d); else if (l> mid) update (mid + 1, R, l, r, rs, d); else {update (L, mid, l, mid, ls, d); update (mid + 1, r, mid + 1, r, rs, d);} mi [k] = min (mi [ls], mi [rs]) + addv [k]; ma [k] = max (ma [ls], ma [rs]) + addv [k];} void getans (int L, int R, int k, int d) {int ls, rs, mid; if (L = R) {Ans [L] = addv [k] + d; return;} ls = k <1; rs = ls | 1; mid = (L + R)> 1; getans (mid + 1, R, rs, d + addv [k]); getans (L, mid, ls, d + addv [k]);} int main () {int n, m, a, B, c, I; while (~ Scanf ("% d", & n, & m, & pp) {btree (1, n, 1); while (m --) {scanf ("% d", & a, & B, & c); update (1, n, a, B, 1, c );} getans (1, n, 1, 0); for (I = 1; I <n; I ++) printf ("% d", ans [I]); printf ("% d \ n", ans [n]);} 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.