【BZOJ 2809】[Apio2012] dispatching

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2809

我是来练习斜堆的 = ̄ω ̄=

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<vector>
#define LL long long
#define abs(x) ((x)>0?(x):-(x))
using namespace std;

const int N = 100000+9;

LL vout;
int led[N],n,m,arr[N],rt;
vector<int> G[N];

inline int read(){
	char c=getchar(); int ret=0,f=1;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') ret=ret*10+c-'0',c=getchar();
	return ret*f;
}

namespace Skew_Heap{
	#define SHP Skew_Heap
	int ch[N][2],sz[N],val[N],root[N],cnt;
	LL sum[N];
	
	inline void maintain(int w) {
		sz[w] = sz[ch[w][0]] + sz[ch[w][1]] + 1;
		sum[w] = sum[ch[w][0]] + sum[ch[w][1]] + val[w];
	}
	
	int Merge(int a, int b){
		if (!a || !b) return a+b;
		else {
			if (val[b] > val[a]) swap(a,b);
			ch[a][1] = Merge(ch[a][1],b);
			swap(ch[a][0],ch[a][1]); maintain(a); 
			return a;
		}
	}
	
	inline void pop(int w){
		root[w] = Merge(ch[root[w]][0],ch[root[w]][1]);
	}
	
	inline void insert(int w, int v){
		val[++cnt] = sum[cnt] = v; sz[cnt] = 1;
		root[w] = Merge(root[w],cnt);
	}
};

int main(){
	using namespace Skew_Heap;
	n = read(); m = read();
	for (int i=1,tmp;i<=n;i++) {
		G[read()].push_back(i);
		arr[i] = read(); led[i] = read();
	}
	for (int i=n;i;i--) {
		for (int j=0,lim=G[i].size();j<lim;j++) root[i] = Merge(root[i],root[G[i][j]]);
		insert(i,arr[i]); while (root[i] && sum[root[i]] > m) pop(i);
		vout = max(vout,(LL)sz[root[i]]*led[i]);
	} 
	printf("%lld\n",vout);
	return 0;
}

28 thoughts to “【BZOJ 2809】[Apio2012] dispatching”

  1. With havin so much content and articles do you ever run into any problems of plagorism or copyright
    violation? My website has a lot of completely unique content I’ve either authored myself or outsourced
    but it looks like a lot of it is popping it up all over the internet
    without my authorization. Do you know any ways to help stop content from being ripped
    off? I’d really appreciate it.

  2. Your style is really unique in comparison to other people I’ve
    read stuff from. Thank you for posting when you have the opportunity,
    Guess I will just book mark this site.

  3. Hey just wanted to give you a quick heads up.
    The words in your article seem to be running off the screen in Internet explorer.
    I’m not sure if this is a formatting issue or something to do with web browser
    compatibility but I figured I’d post to let you know.
    The layout look great though! Hope you get the issue fixed soon.
    Many thanks

  4. whoah this weblog is wonderful i love studying your posts.
    Stay up the good work! You understand, lots of people are searching around for this information, you
    can aid them greatly.

  5. Hi there, I discovered your blog by way of Google even as looking for a related
    matter, your site got here up, it looks great.
    I have bookmarked it in my google bookmarks.
    Hi there, just became alert to your blog through Google, and found that it’s
    truly informative. I’m going to watch out for brussels. I will appreciate for those who proceed this in future.
    Numerous other people can be benefited from your writing.
    Cheers!

  6. I’m extremely impressed with your writing abilities and also
    with the format in your weblog. Is this a paid topic or did you customize it yourself?
    Anyway stay up the nice high quality writing, it’s uncommon to peer a nice blog like this one these days..

  7. Hello there, just became alert to your blog through Google, and found
    that it is truly informative. I’m going to watch out for brussels.
    I’ll be grateful if you continue this in future. Numerous
    people will be benefited from your writing. Cheers!

  8. We are a group of volunteers and opening a new scheme in our community.
    Your website offered us with valuable info to work on. You
    have done a formidable job and our whole community will be grateful to you.

  9. An outstanding share! I have just forwarded this onto a co-worker who was doing
    a little research on this. And he actually
    bought me dinner simply because I found it for him…
    lol. So allow me to reword this…. Thank YOU for
    the meal!! But yeah, thanks for spending the time to talk about
    this issue here on your internet site.

  10. Very nice post. I just stumbled upon your weblog and wanted to say
    that I’ve truly enjoyed browsing your blog posts. In any case
    I’ll be subscribing to your rss feed and I hope you write again very soon!

  11. Every weekend i used to pay a quick visit this site,
    for the reason that i wish for enjoyment, as this this site conations
    genuinely pleasant funny material too.

  12. I know this if off topic but I’m looking into starting my own blog and was curious what all is
    needed to get set up? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet savvy so I’m not 100% certain. Any suggestions or advice would be greatly appreciated.
    Kudos

  13. Thanks for your marvelous posting! I seriously enjoyed reading it,
    you’re a great author.I will be sure to bookmark your blog and may come back later in life.
    I want to encourage yourself to continue your great work, have a nice day!

  14. I’ve been exploring for a bit for any high quality articles or weblog posts on this kind of space .
    Exploring in Yahoo I finally stumbled upon this web site.

    Studying this information So i am glad to exhibit
    that I have a very excellent uncanny feeling I found out just what I needed.
    I such a lot undoubtedly will make certain to don?t omit this web site and provides it a look regularly.

  15. Good post however I was wondering if you could write a litte
    more on this subject? I’d be very grateful if you could elaborate a little
    bit further. Thank you!

  16. Whats up this is somewhat of off topic but I was wanting to know
    if blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding skills so I
    wanted to get advice from someone with experience. Any help would be
    greatly appreciated!

  17. Generally I don’t learn post on blogs, however I wish to say that this write-up very compelled me to check out and
    do so! Your writing style has been surprised me. Thanks, very
    nice post.

  18. I really wanted to make a brief message to be able to express gratitude to you for the magnificent tips and tricks you are showing here. My incredibly long internet research has finally been rewarded with awesome information to write about with my companions. I would repeat that we website visitors actually are undeniably fortunate to live in a decent network with many lovely people with valuable tactics. I feel truly fortunate to have encountered the web pages and look forward to tons of more amazing times reading here. Thanks a lot once more for all the details.

Leave a Reply

Your email address will not be published. Required fields are marked *