【AtCoder】[Grand Contest 015 E] Mr.Aoki Incubator

相关链接

题目传送门:http://agc015.contest.atcoder.jp/tasks/agc015_e

解题报告

我们发现:对于任意一个时刻,一个病原体引发的感染者一定是一个区间
那么问题转化为选一些线段来覆盖整个序列,这个用可以线性维护
总的时间复杂度:$O(n \log n)$

Code

#include<bits/stdc++.h>
#define LL long long
#define lowbit(x) ((x)&-(x))
using namespace std;
 
const int N = 200009;
const int MOD = 1000000007;
 
int n, np[N], arr[N];
struct Data{
	int x, v; 
	inline bool operator < (const Data &D) const {
		return x < D.x || (x == D.x && v < D.v);
	}
}d[N], seg[N];
 
inline int read() {
	char c = getchar(); int ret = 0, f = 1;
	for (; c < '0' || c > '9'; f = c == '-'? -1: 1, c = getchar());
	for (; '0' <= c && c <= '9'; ret = ret * 10 + c - '0', c = getchar());
	return ret * f;
}
 
inline bool cmpv(int aa, int bb) {
	return d[aa].v < d[bb].v;
}
 
class Fenwick_Tree{
	int sum[N], uve, cur = 1;
public:
	inline void modify(int p, int x) {
		uve = (uve + x) % MOD;
		sum[p] = (sum[p] + x) % MOD;
	}	
	inline int query(int p) {
		while (cur < p) {
			++cur;
			sum[cur] = (sum[cur] + sum[cur - 1]) % MOD;
		}
		return ((uve - sum[p - 1]) + MOD) % MOD;
	}
}BIT;
 
int main() {
	n = read();
	for (int i = 1; i <= n; i++) {
		d[i].x = read();
		d[i].v = read();
		arr[i] = i;
	}
	sort(d + 1, d + 1 + n);
	sort(arr + 1, arr + 1 + n, cmpv);
	for (int i = 1; i <= n; i++) {
		np[arr[i]] = i;
	}
	for (int i = 1, cur = 0; i <= n; ++i) {
		seg[i].x = cur = max(cur, np[i]);
	}
	for (int i = n, cur = n + 1; i; --i) {
		seg[i].v = cur = min(cur, np[i]);
	}
	sort(seg + 1, seg + 1 + n);
	BIT.modify(1, 1);
	for (int i = 1; i <= n; i++) {
		int tmp = BIT.query(seg[i].v);
		BIT.modify(seg[i].x + 1, tmp);
	}
	printf("%d\n", BIT.query(n + 1));
	return 0;
}

76 thoughts to “【AtCoder】[Grand Contest 015 E] Mr.Aoki Incubator”

  1. I’m amazed, I must say. Seldom do I encounter a blog that’s
    both equally educative and interesting, and let me tell you, you have
    hit the nail on the head. The problem is an issue that too few men and women are speaking intelligently about.
    I’m very happy that I came across this in my search for something regarding this.

  2. Hey there! 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 website covers a lot of the same subjects as yours and I think
    we could greatly benefit from each other. If you might be interested feel free to
    shoot me an e-mail. I look forward to hearing from you! Great
    blog by the way!

  3. You actually make it seem so easy with your presentation but I find this
    matter to be actually something that I think I would never understand.
    It seems too complicated and extremely broad for me.

    I am looking forward for your next post, I’ll try to get the hang of it!

  4. Thank you a bunch for sharing this with all folks you really realize what you are speaking approximately!
    Bookmarked. Please also visit my site =). We may have
    a hyperlink trade contract among us

  5. Hello! Do you know if they make any plugins
    to help with Search Engine Optimization? I’m trying to get my blog
    to rank for some targeted keywords but I’m not seeing very good results.

    If you know of any please share. Appreciate it!

  6. Excellent post. I was checking constantly this blog and I
    am impressed! Very useful info specially the last section 🙂 I care for such
    info much. I was looking for this certain information for a very lengthy
    time. Thank you and best of luck.

  7. Hello there! I could have sworn I’ve been to this website before
    but after going through some of the posts I realized it’s new to me.
    Nonetheless, I’m definitely delighted I stumbled upon it and I’ll be book-marking it and
    checking back regularly!

  8. Thanks for one’s marvelous posting! I quite enjoyed reading it, you
    might be a great author. I will remember to bookmark your blog and definitely
    will come back down the road. I want to encourage you to definitely continue your great work, have
    a nice day!

  9. My brother recommended I may like this blog.

    He was entirely right. This publish actually made my day.
    You cann’t imagine simply how much time I had spent for this info!
    Thanks! natalielise pof

  10. Howdy great blog! Does running a blog such as this
    require a massive amount work? I’ve absolutely no expertise in computer
    programming but I was hoping to start my own blog in the near future.

    Anyways, should you have any ideas or techniques for new blog
    owners please share. I understand this is off subject but I
    just needed to ask. Appreciate it!

  11. Yesterday, while I was at work, my sister stole my apple ipad and tested to
    see if it can survive a forty foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views.

    I know this is totally off topic but I had to share it with someone!

  12. My brother suggested I might like this website.
    He was totally right. This post actually made my day.
    You can not imagine just how much time I had spent for this information! Thanks!

  13. Hey! Someone in my Myspace group shared this website with us so I
    came to check it out. I’m definitely loving the information. I’m book-marking and
    will be tweeting this to my followers! Wonderful
    blog and great design.

  14. Hey there! I know this is kinda off topic nevertheless I’d figured I’d ask.

    Would you be interested in exchanging links or maybe guest
    writing a blog article or vice-versa? My blog covers a
    lot of the same topics as yours and I feel 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!

  15. Hi! I just wanted to ask if you ever have any trouble with hackers?

    My last blog (wordpress) was hacked and I ended up losing months of hard work due to no data backup.
    Do you have any solutions to stop hackers?

  16. Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s hard to
    get that “perfect balance” between user friendliness and visual appeal.

    I must say you have done a superb job with
    this. Additionally, the blog loads very quick for me on Internet explorer.
    Superb Blog!

  17. You really make it seem so easy with your presentation but I find this matter to
    be really something which I think I would never understand.
    It seems too complex and extremely broad for me. I’m looking forward
    for your next post, I’ll try to get the hang
    of it!

  18. This design is wicked! You most certainly know how to keep a
    reader amused. Between your wit and your videos, I was almost moved to start my own blog (well,
    almost…HaHa!) Wonderful job. I really loved what you had to say, and more than that,
    how you presented it. Too cool!

  19. Hey terrific website! Does running a blog like this take a great
    deal of work? I’ve virtually no expertise in programming but I had been hoping
    to start my own blog in the near future. Anyway, should you have any ideas or
    tips for new blog owners please share. I know this is off topic but I just had to
    ask. Thanks!

  20. I was very pleased to find this page. I need to to thank you
    for your time due to this wonderful read!!

    I definitely appreciated every part of it and I have you
    saved to fav to check out new information on your website.

  21. Howdy just wanted to give you a brief heads up and let
    you know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a linking issue.

    I’ve tried it in two different browsers and both show the
    same results.

  22. Oh my goodness! Amazing article dude! Thank you so much, However I am
    encountering issues with your RSS. I don’t understand the reason why
    I can’t subscribe to it. Is there anybody having similar RSS problems?
    Anybody who knows the solution can you kindly respond? Thanks!!

  23. Woah! I’m really enjoying the template/theme of
    this website. It’s simple, yet effective. A
    lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal.
    I must say you have done a superb job with this. Also, the blog loads very quick for me on Firefox.

    Outstanding Blog!

  24. I have been surfing on-line more than 3 hours lately,
    but I by no means discovered any interesting article like yours.
    It is pretty price enough for me. Personally, if all site owners and
    bloggers made just right content as you did,
    the internet will probably be a lot more useful than ever
    before.

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

  26. Terrific work! This is the type of info that should be shared
    around the web. Disgrace on Google for not positioning this post upper!

    Come on over and visit my website . Thanks =)

  27. Hey very nice website!! Man .. Beautiful .. Wonderful ..
    I will bookmark your blog and take the feeds
    additionally? I’m happy to find numerous helpful info right here within the submit,
    we want work out extra strategies in this regard, thank you for sharing.

    . . . . .

  28. I just like the helpful info you supply on your articles.
    I’ll bookmark your blog and take a look at once
    more here frequently. I am quite certain I’ll be informed a lot of
    new stuff proper here! Best of luck for the following!

  29. 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
    waste your intelligence on just posting videos to your blog when you could be giving us something informative to read?

  30. The other day, while I was at work, my cousin stole my apple ipad and tested to
    see if it can survive a 25 foot drop, just so she can be a youtube sensation. My apple
    ipad is now broken and she has 83 views. I know this is entirely off topic but I had to share
    it with someone!

  31. Hi there i am kavin, its my first time to commenting anywhere, when i read this piece of writing i thought i
    could also create comment due to this sensible article.

  32. I all the time used to study piece of writing in news papers but now
    as I am a user of web so from now I am using net for articles,
    thanks to web.

  33. Hi, There’s no doubt that your website could possibly be having browser compatibility problems.
    Whenever I take a look at your blog in Safari, it looks fine however, when opening in I.E., it’s got
    some overlapping issues. I merely wanted to give you
    a quick heads up! Besides that, excellent
    website!

  34. We’re a gaggle of volunteers and starting a brand new scheme in our community.
    Your website provided us with valuable information to work on. You have performed a formidable job
    and our entire community will be thankful to you.

  35. hi!,I really like your writing very much! percentage we communicate more about your article on AOL? I need a specialist on this area to unravel my problem. May be that’s you! Taking a look forward to look you.

Leave a Reply

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