【UOJ 77】A+B Problem

相关链接

题目传送门:http://uoj.ac/problem/77
神犇题解:http://www.cnblogs.com/geng4512/p/5296863.html

解题报告

我们发现如果忽略\(1<j<i\)这个限制,再假设\({l_i} = {r_i}\)
这样的话,直接上最小割就好

现在考虑\({l_i} < {r_i}\)
这样的话,用线段树优化建图就可以啦!

再考虑\(1<j<i\)这个限制
这样的话,用函数式线段树就可以啦!

感觉是VFK强行套数据结构啊!
另外还有BZOJ 3218可以双倍经验!
话说BZOJ上那些\(200ms+\)的神犇都是用的什么算法啊?
怎么这么快啊!

Code

#include<bits/stdc++.h>
using namespace std;

const int N = 200000+9;
const int M = 2000000;
const int INF = 1000000000;

int n,m,S,T,vout,head[N],nxt[M],to[M],flow[M];
int tot,_hash[N],A[N],W[N],B[N],LL[N],RR[N],P[N];

inline int read() {
	char c=getchar(); int f=1,ret=0;
	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;
}

inline void Add_Edge(int u, int v, int f = INF, int t = 0) {
	static int E = 1; vout += f * t;
	to[++E] = v; nxt[E] = head[u]; head[u] = E; flow[E] = f;
	to[++E] = u; nxt[E] = head[v]; head[v] = E; flow[E] = 0;
}

class Network_Flow{
    int cur[N],dis[N];
    queue<int> que;
    public:
        inline int MaxFlow() {
            int ret = 0;
            while (BFS()) {
                memcpy(cur, head, sizeof(head));
                ret += DFS(S, INF);
            }   
            return ret;
        }
    private:
        inline bool BFS() {
            memset(dis,60,sizeof(dis));
            que.push(S); dis[S] = 0;
              
            while (!que.empty()) {
                int w = que.front(); que.pop();
                for (int i=head[w];i;i=nxt[i]) {
                    if (dis[to[i]] > INF && flow[i]) {
                        dis[to[i]] = dis[w] + 1;
                        que.push(to[i]);
                    }
                }
            }
            return dis[T] < INF;
        }
        int DFS(int w, int f) {
            if (w == T) return f;
            else {
                int ret = 0;
                for (int tmp,&i=cur[w];i;i=nxt[i]) {
                    if (dis[to[i]] == dis[w] + 1 && flow[i]) {
                        tmp = DFS(to[i], min(f, flow[i])); 
                        flow[i] -= tmp; flow[i^1] += tmp;
                        f -= tmp; ret += tmp;
                        if (!f) break;
                    }
                }
                return ret;
            }
        }
}Dinic;

namespace Persistent_Segment_Tree{
	#define PST Persistent_Segment_Tree
	int ch[N][2],root[N],cnt,pur,sur,L,R;
	
	void insert(int p, int &w, int l, int r, int f = 0) {
		if (w = ++cnt, p) {
			ch[w][0] = ch[p][0];
			ch[w][1] = ch[p][1];
			Add_Edge(p, w);
		} 
		if (f) Add_Edge(w, f);
		if (l < r) {
			int mid = l + r + 1 >> 1;
			if (pur < mid) insert(ch[p][0], ch[w][0], l, mid-1, w);
			else insert(ch[p][1], ch[w][1], mid, r, w);
		} else Add_Edge(sur, w);
	}
	
	inline void insert(int p, int v) {
		pur = v; sur = p;
		insert(root[p-1], root[p], 1, tot);
	}
	
	void modify(int w, int l, int r) {
		if (!w) return;
		else if (L <= l && r <= R) Add_Edge(w, pur);
		else {
			int mid = l + r + 1 >> 1;
			if (L < mid) modify(ch[w][0], l, mid-1);
			if (mid <= R) modify(ch[w][1], mid, r);
		}
	}
	
	inline void modify(int p, int node, int l, int r) {
		pur = node; L = l; R = r;
		modify(root[p], 1, tot);
	}
};

int main() {
	n = read(); PST::cnt = n << 1;
	S = 0; T = N - 1;
	for (int i=1;i<=n;i++) {
		_hash[++tot] = A[i] = read(); 
		B[i] = read();
		W[i] = read();
		_hash[++tot] = LL[i] = read();
		_hash[++tot] = RR[i] = read();
		P[i] = read();
	}
	sort(_hash+1, _hash+1+tot);
	tot = unique(_hash+1, _hash+1+tot) - _hash - 1;
	for (int i=1;i<=n;i++) {
		A[i] = lower_bound(_hash+1, _hash+1+tot, A[i]) - _hash;
		LL[i] = lower_bound(_hash+1, _hash+1+tot, LL[i]) - _hash;
		RR[i] = lower_bound(_hash+1, _hash+1+tot, RR[i]) - _hash;
	}
	for (int i=1,l,r;i<=n;i++) {
		PST::insert(i, A[i]);
		Add_Edge(i, T, B[i], 1);
		Add_Edge(S, i, W[i], 1);
		PST::modify(i-1, i+n, LL[i], RR[i]);
		Add_Edge(i+n, i, P[i]);
	}
	printf("%d\n",vout-Dinic.MaxFlow());
	return 0;
}

78 thoughts to “【UOJ 77】A+B Problem”

  1. You could certainly see your enthusiasm within the article you write.
    The world hopes for more passionate writers such
    as you who aren’t afraid to mention how they believe. All the time go after your heart.

  2. Hello there I am so glad I found your web site, I really
    found you by mistake, while I was researching on Google for something else, Anyways I am here
    now and would just like to say kudos for a marvelous post and a all round thrilling blog (I also love the theme/design), I don’t have
    time to read it all at the moment but I have bookmarked it and also added in your RSS feeds, so when I have time I
    will be back to read a lot more, Please do keep up the excellent jo.

  3. Hi there, I discovered your web site by the use of
    Google even as looking for a comparable matter,
    your web site came up, it looks great. I’ve bookmarked it in my google bookmarks.

    Hi there, simply changed into aware of your weblog via Google,
    and found that it’s really informative. I’m gonna watch out for brussels.
    I will appreciate in the event you proceed this in future.
    Lots of folks might be benefited from your writing.

    Cheers!

  4. Someone necessarily assist to make severely articles I’d
    state. This is the very first time I frequented your
    web page and so far? I surprised with the research you made to make this particular put up amazing.
    Excellent activity!

  5. Greetings from Florida! I’m bored to tears at work so I decided to check out your site on my iphone
    during lunch break. I really like the knowledge you present here and can’t wait to take a look when I get home.
    I’m shocked at how fast your blog loaded on my cell phone ..
    I’m not even using WIFI, just 3G .. Anyhow, excellent site!

  6. I’ve been browsing online more than 3 hours today, yet
    I never found any interesting article like yours.
    It’s pretty worth enough for me. In my opinion, if all website owners and bloggers made
    good content as you did, the internet will be much more useful than ever before.

  7. Hey I know this is off topic but I was wondering if you knew
    of any widgets I could add to my blog that automatically
    tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to
    your new updates.

  8. I’m really impressed along with your writing talents and also with the layout in your blog.
    Is this a paid subject matter or did you customize it your self?

    Anyway stay up the nice quality writing, it’s uncommon to peer a great weblog like this one these days..

  9. Hey! I know this is kinda off topic however I’d figured I’d ask.
    Would you be interested in trading links or maybe guest
    authoring a blog article or vice-versa? My blog goes
    over a lot of the same topics as yours and I think we could greatly benefit from each other.

    If you might be interested feel free to send me an e-mail.
    I look forward to hearing from you! Fantastic blog by the way!

  10. Hey! I know this is somewhat off topic but I
    was wondering which blog platform are you using for this website?
    I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at options for
    another platform. I would be great if you could point me in the direction of a good platform.

  11. Howdy, There’s no doubt that your website could possibly be having browser compatibility issues.
    When I take a look at your blog in Safari, it looks fine but when opening
    in IE, it has some overlapping issues. I merely wanted to provide
    you with a quick heads up! Other than that, great site!

  12. Hey there! Someone in my Facebook group shared this website
    with us so I came to take a look. I’m definitely loving the information. I’m
    bookmarking and will be tweeting this to my followers!
    Terrific blog and wonderful design.

  13. hello there and thank you for your info – I’ve definitely picked up something new from right here.
    I did however expertise a few technical points using this web site, as
    I experienced to reload the web site many times previous to I could get it to load
    correctly. I had been wondering if your web hosting is OK?

    Not that I am complaining, but sluggish loading instances times will often affect your placement in google and could damage your high-quality score if advertising and marketing with Adwords.
    Anyway I am adding this RSS to my email and could look out
    for a lot more of your respective interesting content. Ensure that you update this again soon.

  14. What’s up i am kavin, its my first time to commenting anywhere, when i read this post i thought i could also make comment due to
    this brilliant article.

  15. Hi there very nice blog!! Man .. Beautiful ..

    Amazing .. I will bookmark your site and take the feeds additionally?
    I’m glad to search out numerous useful info right here
    within the publish, we’d like develop extra strategies in this regard, thanks for sharing.
    . . . . .

  16. You are so awesome! I don’t suppose I’ve read through a single thing like that before.
    So nice to discover another person with some unique thoughts on this issue.
    Seriously.. thanks for starting this up. This site is one thing that
    is required on the web, someone with a bit of originality!
    natalielise plenty of fish

  17. Hi there! This article couldn’t be written any better! Going through this article reminds
    me of my previous roommate! He constantly kept talking about this.
    I will send this post to him. Fairly certain he’s going to have a very good read.
    Thanks for sharing!

  18. Hmm it appears like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly
    enjoying your blog. I too am an aspiring blog blogger but I’m still new
    to the whole thing. Do you have any helpful hints
    for beginner blog writers? I’d genuinely appreciate it.

  19. Thanks for ones marvelous posting! I really enjoyed reading it, you could be a great author.I will make sure to
    bookmark your blog and definitely will come back at some point.
    I want to encourage that you continue your great work,
    have a nice holiday weekend!

  20. I love your blog.. very nice colors & theme.
    Did you create this website yourself or did you hire someone to do it for
    you? Plz respond as I’m looking to design my
    own blog and would like to find out where u got this from.
    appreciate it

  21. Have you ever considered writing an ebook or guest authoring on other blogs?

    I have a blog centered on the same subjects you discuss and would love to have you share some stories/information. I know my readers would value your
    work. If you are even remotely interested, feel free to shoot me an e mail.

  22. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
    You definitely know what youre talking about, why throw away your intelligence on just posting videos to your blog when you could be giving us something informative to read?

  23. Its like you learn my mind! You seem to know a lot approximately this, like you wrote the e book in it or
    something. I think that you simply could do with some percent to pressure the
    message house a little bit, but instead of that, that is great blog.

    An excellent read. I will definitely be back.

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

  25. Howdy! This blog post could not be written any better!
    Reading through this post reminds me of my previous roommate!
    He constantly kept talking about this. I most certainly will send this post to him.
    Fairly certain he’ll have a great read. I appreciate you
    for sharing!

  26. When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is
    added I get four emails with the same comment. Is there any way you can remove me from that service?
    Cheers!

  27. Hi! This post couldn’t be written any better! Reading through this post reminds
    me of my old room mate! He always kept chatting about this.
    I will forward this page to him. Fairly certain he will have a good read.
    Thank you for sharing!

  28. I think this is among the most important information for me.
    And i’m glad reading your article. But should remark on few general things, The site style is ideal, the articles is
    really excellent : D. Good job, cheers

  29. This is really interesting, You are a very skilled blogger.

    I have joined your feed and look forward to seeking more
    of your excellent post. Also, I’ve shared your web site in my social networks!

  30. This is really interesting, You are a very skilled blogger.
    I’ve joined your feed and look forward to seeking more of your excellent post.
    Also, I’ve shared your website in my social networks!

  31. Great post. I was checking continuously this weblog and I am inspired!
    Extremely useful info specifically the closing part 🙂 I care
    for such info a lot. I was looking for this certain info for a long time.
    Thank you and best of luck.

  32. Simply wish to say your article is as astounding.
    The clarity for your post is just nice and i could assume you’re a professional on this subject.
    Fine along with your permission allow me to take hold of
    your feed to stay up to date with drawing close post. Thanks 1,000,000 and please continue the gratifying work.

  33. You actually make it appear really easy with your presentation but I find this
    matter to be really something which I feel I’d by no means understand.
    It seems too complicated and very wide for me.

    I am taking a look ahead on your next put up, I will attempt to get the dangle of it!

  34. I am curious to find out what blog system you
    have been using? I’m having some minor security issues with my
    latest website and I would like to find something more safeguarded.

    Do you have any recommendations?

  35. May I simply say what a relief to find somebody who
    truly understands what they are discussing on the internet.
    You actually realize how to bring an issue to light and make it important.
    More people really need to look at this and understand this side of your story.
    It’s surprising you are not more popular given that you definitely
    have the gift.

  36. My spouse and I stumbled over here different web address and thought I might as well
    check things out. I like what I see so i am just following you.
    Look forward to looking into your web page repeatedly.

  37. fantastic points altogether, you simply received a logo new reader. What may you suggest about your publish that you simply made some days in the past? Any sure?

  38. Write more, thats all I have to say. Literally, it seems as though you relied on the video to
    make your point. You clearly know what youre talking about, why throw away your intelligence on just posting
    videos to your site when you could be giving us something enlightening to read?

  39. Hey I know this is off topic but I was wondering if you knew of any widgets
    I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some
    time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

  40. Wonderful beat ! I would like to apprentice while you
    amend your site, how could i subscribe for a blog web
    site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright
    clear concept

  41. Your style is so unique in comparison to other people I have read stuff from.
    I appreciate you for posting when you have the opportunity, Guess I will just bookmark this blog.

  42. Can I simply just say what a relief to discover an individual who really knows what they are talking about on the web.
    You definitely understand how to bring an issue
    to light and make it important. More people need to look at this and understand
    this side of the story. I was surprised you are not more popular since you
    definitely have the gift.

  43. Great goods from you, man. I have understand your stuff previous to and you
    are just too magnificent. I really like what you’ve acquired here, really like what you are saying and the
    way in which you say it. You make it entertaining
    and you still take care of to keep it wise. I cant wait
    to read much more from you. This is actually a terrific web site.

  44. Hello There. I found your blog using msn. This is a really
    well written article. I’ll be sure to bookmark it and come back to read more of your useful info.
    Thanks for the post. I’ll certainly return.

  45. I’m not sure why but this weblog is loading incredibly slow
    for me. Is anyone else having this issue or is it a issue on my end?
    I’ll check back later on and see if the problem still exists.

  46. of course like your website but you need to check the spelling on several of your posts. Several of them are rife with spelling issues and I find it very bothersome to tell the truth nevertheless I’ll certainly come back again.

Leave a Reply

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