Hdu 3954 Level up (line segment tree)

Source: Internet
Author: User

HH. You can only worship it all the time...

Starting from the line tree, he learned 1.1 drops from his blog.

The style is also based on him.

Then let's talk about the question.

There will be a lot of monster attacks, and then there will be N heroes. Not a wave of monsters sent number is L-R hero to welcome the enemy.

Each hero will gain a certain degree of experience (both level * experience base E of each wave ). The last Q operation is to ask which hero in the L-R segment has the highest experience and outputs the highest value.

 


At the beginning, I confused the question. If he had gained enough experience to raise his level, he would immediately upgrade his level after obtaining the experience, and his level would change after the upgrade.

Calculate the remaining experience based on the new level. That is, the snowball rolls bigger and bigger. Then I asked the students of the minimum public multiple ~~~ Zookeeper

 


When I write it myself, I directly push the LAZY (cov array) down. Then I realized that such lazy could not be directly superimposed, because after multiple operations, his level would change.

The previous mark is useless. Then I want. I will push down the previous cov every time I come. But obviously this is like a single-point update.

 


Through the above paragraph, we should be able to understand the usage of the dis variable in the code.

 


Dis refers to the experience base required by a hero who requires at least experience in the interval. In other words, if this person cannot be upgraded, no one will be able to upgrade in this range.

Then you can directly add the cov.

This individual can be upgraded within the specified range. We thought that a certain person in this section had a change in the time when we had to push down this cov. Find the person who has changed. Then update the interval.

 

# Include <iostream> # include <cstdio> # include <algorithm> # define lson num <1, s, mid # define rson num <1 | 1, mid + 1, e # define maxn 10005 using namespace std; int exp [maxn <2], lev[ maxn <2]; // maximum level of the maximum empirical range of the interval int cov [maxn <2], dis [maxn <2]; // lazy mark the array dis as above int ned [15] = {0}; int K; void pushup (int num) {exp [num] = max (exp [num <1], exp [num <1 | 1]); * [num] = max (* [num <1], * [num <1 | 1]); dis [num] = min (dis [num <1], dis [num <1 | 1]);} int getlev( int ex) // locate the level of experience {if (ex> = ned [K-1]) return K; for (int I = 1; I <= K; I ++) {if (ex <ned [I]) return I ;}} void pushdown (int num) {if (cov [num]) {cov [num <1 | 1] + = cov [num]; cov [num <1] + = cov [num]; exp [num <1] + = (cov [num] * lev_[ num <1]); exp [num <1 | 1] + = (cov [num] * lev[ num <1 | 1]); dis [num <1]-= cov [num]; dis [num <1 | 1]-= cov [num]; cov [num] = 0 ;}} void build (int num, int s, int e) {exp [num] = 0; lev[ num] = 1; cov [Num] = 0; dis [num] = ned [1]; if (s = e) return; int mid = (s + e)> 1; build (lson); build (rson);} void update (int num, int s, int e, int l, int r, int val) {int mid = (s + e)> 1; if (s = e) {exp [num] + = lev[ num] * val; lev_[ num] = getlev_( exp [num]); dis [num] = (ned [lev_[ num]-exp [num])/(lev_[ num]) + (ned [column [num]-exp [num]) % (column [num])! = 0); return;} if (l <= s & r> = e) {if (val <dis [num]) {exp [num] + = lev[ num] * val; dis [num]-= val; cov [num] + = val; return;} else {pushdown (num ); update (lson, s, mid, val); update (rson, mid + 1, e, val); pushup (num); return ;}} pushdown (num ); if (l <= mid) update (lson, l, r, val); if (r> mid) update (rson, l, r, val ); pushup (num);} int query (int num, int s, int e, int l, int r) {if (s> = l & e <= r) {return exp [num];} pushdown (num); int mid = (s + e)> 1; if (r <= mid) return query (lson, l, r); else if (l> mid) return query (rson, l, r); else return max (query (lson, l, mid), query (rson, mid + 1, r);} int main () {int T, CASE = 1; scanf ("% d", & T); while (T --) {printf ("Case % d: \ n", CASE ++); int n, qw; scanf ("% d", & n, & K, & qw); for (int I = 1; I <K; I ++) {scanf ("% d", & ned [I]);} ned [K] = 1 <30; build (1,1, n); while (qw --) {char tope [5]; scanf ("% s", tope ); if (tope [0] = 'W') {int a, B, c; scanf ("% d", & a, & B, & c); update (1, 1, n, a, B, c);} else {int a, B; scanf ("% d", &, & B); printf ("% d \ n", query (, n, a, B) ;}} puts ("") ;}return 0 ;} /* 55 5 9992 10 15 16 W 1 3 1 W 1 2 1Q 1 1 */

 

Related Article

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.