【Codeforces 712E】Memory and Casinos

题目传送门:http://codeforces.com/problemset/problem/712/E
官方题解:http://codeforces.com/blog/entry/47050

这个题目想一想,还是挺好玩的
推导过程比较复杂,参见这里吧:http://codeforces.com/blog/entry/47050?#comment-314259
话说这次的官方题解真是辣鸡,还不如评论区容易懂…..

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

const int N = 200000+9;

int n,m;
double arr[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 Segment_Tree{
	#define SEG Segment_Tree
	int ch[N][2],cnt,root,T1,L,R;
	double t1[N],t2[N],T2,ans_tmp;
	
	inline void maintain(int w){
		t1[w] = t1[ch[w][0]] * t1[ch[w][1]];
		t2[w] = t2[ch[w][0]] + t2[ch[w][1]] * t1[ch[w][0]];
	}
	
	void Build(int &w, int l, int r) {
		w = ++cnt;
		if (l == r) {
			t1[w] = t2[w] = arr[l];
		} else {
			int mid = l + r + 1 >> 1;
			Build(ch[w][0],l,mid-1);
			Build(ch[w][1],mid,r);
			maintain(w);
		}
	}
	
	void modify(int w, int l, int r) {
		if (l == r) {
			t1[w] = t2[w] = T2;
		} else {
			int mid = l + r + 1 >> 1;
			if (T1 < mid) modify(ch[w][0],l,mid-1);
			else modify(ch[w][1],mid,r);
			maintain(w);
		}
	}
	
	inline void modify(int pos, double nv) {
		T1 = pos; T2 = nv;
		modify(root,1,n);
	}
	
	void query(int w, int l, int r) {
		if (L <= l && r <= R) {
			ans_tmp += t2[w] * T2;
			T2 *= t1[w];
		} else {
			int mid = l + r + 1 >> 1;
			if (L < mid) query(ch[w][0],l,mid-1);
			if (mid <= R) query(ch[w][1],mid,r);
		}
	}
	
	inline double query(int l, int r) {
		ans_tmp = 0; T2 = 1;
		L = l; R = r;
		query(root,1,n);
		return ans_tmp;
	}
};

int main(){
	n = read(); m = read();
	for (int i=1,a,b;i<=n;i++) {
		a = read(); b = read();
		double tmp = (double)a/b;
		arr[i] = (1 - tmp) / tmp;
	}
	SEG::Build(SEG::root,1,n);
	for (int i=1,a,b,c,ty;i<=m;i++) {
		ty = read(); a = read(); b = read();
		if (ty == 1) {
			c = read();
			double tmp = (double)b/c;
			SEG::modify(a,(1-tmp)/tmp);
		} else {
			double tmp = SEG::query(a,b);
			tmp = min(1e20,tmp);
			printf("%.10lf\n",1/(1+tmp));
		}
	}
	return 0;
}

81 thoughts to “【Codeforces 712E】Memory and Casinos”

  1. Attractive section of content. I just stumbled upon your web site and in accession capital to assert that I
    get in fact enjoyed account your blog posts.
    Any way I’ll be subscribing to your feeds and even I achievement you access consistently fast.

  2. I’m really loving the theme/design of your website.
    Do you ever run into any browser compatibility issues? A handful
    of my blog audience have complained about my blog not working correctly in Explorer but looks great
    in Firefox. Do you have any suggestions to help fix this problem?

  3. Hey there, I think your blog might be having browser compatibility
    issues. When I look at your blog site in Safari, it looks fine but
    when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, wonderful blog!

  4. Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed browsing your blog
    posts. After all I’ll be subscribing to your feed and I hope you write again soon!

  5. Pretty great post. I just stumbled upon your weblog and wished to say that I’ve truly loved browsing your weblog
    posts. After all I’ll be subscribing on your feed
    and I am hoping you write again soon!

  6. Oh my goodness! Incredible article dude! Thank you,
    However I am experiencing troubles with your RSS.
    I don’t understand why I cannot join it. Is there anybody else having identical RSS issues?

    Anyone who knows the solution will you kindly respond? Thanx!!

  7. It is the best time to make some plans for the long run and it
    is time to be happy. I have learn this publish and if I may just I wish to suggest you few fascinating things or tips.
    Perhaps you could write subsequent articles regarding this article.
    I wish to learn more issues approximately it!

  8. I’m impressed, I have to admit. Rarely do I encounter a blog that’s both educative and entertaining, and without
    a doubt, you have hit the nail on the head.
    The problem is something that not enough folks are speaking intelligently
    about. I’m very happy that I came across this during my search for something
    concerning this. plenty of fish natalielise

  9. Excellent items from you, man. I’ve have in mind your stuff prior to and
    you are just too excellent. I actually like what you have acquired right here,
    certainly like what you are saying and the way
    through which you assert it. You’re making it enjoyable
    and you still take care of to keep it smart. I can not wait
    to read much more from you. This is really a wonderful
    site. natalielise pof

  10. Great post but I was wanting to know if you could write a
    litte more on this topic? I’d be very thankful if you
    could elaborate a little bit further. Bless you!

  11. I was suggested this blog by my cousin. I am now not
    certain whether this post is written through him
    as nobody else know such special approximately my difficulty.
    You are amazing! Thank you!

  12. My spouse and I stumbled over here by a different page and thought I may as well check things
    out. I like what I see so now i’m following you. Look
    forward to looking over your web page yet again.

  13. Do you have a spam problem on this website; I also am a blogger, and I was wondering your situation; many of us have created some nice practices and we
    are looking to swap methods with others, please shoot me an e-mail if interested.

  14. My brother recommended I would possibly like
    this blog. He was entirely right. This post truly made my day.
    You cann’t believe just how so much time I had spent
    for this information! Thanks!

  15. Hello there! I could have sworn I’ve been to your blog before but after looking at a
    few of the articles I realized it’s new to me. Nonetheless, I’m definitely delighted I stumbled upon it and I’ll be bookmarking it and checking back frequently!

  16. I was recommended this web site by my cousin. I’m not sure whether this post
    is written by him as nobody else know such detailed about my difficulty.
    You are incredible! Thanks!

  17. When I initially commented I seem to have clicked on the -Notify me
    when new comments are added- checkbox and now each time a
    comment is added I receive 4 emails with the exact same comment.
    Perhaps there is an easy method you are able to remove
    me from that service? Thanks a lot!

  18. I’m amazed, I have to admit. Seldom do I come across a blog
    that’s both equally educative and entertaining, and
    without a doubt, you have hit the nail on the head.
    The problem is an issue that not enough folks are speaking intelligently about.
    I am very happy I found this during my search for something
    concerning this.

  19. Good post. I learn something new and challenging on websites I stumbleupon every day.
    It will always be useful to read through articles from other authors and use a little something from
    other web sites.

  20. Hi 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 authoring a blog post
    or vice-versa? My blog goes over 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 shoot me an e-mail.
    I look forward to hearing from you! Excellent blog by
    the way!

  21. magnificent post, very informative. I ponder why the opposite experts of this sector do not notice this.
    You should continue your writing. I am confident, you have a huge
    readers’ base already!

  22. Great beat ! I wish to apprentice while you amend your site, how could i subscribe for
    a blog website? The account aided me a acceptable deal.
    I had been a little bit acquainted of this your
    broadcast provided bright clear idea

  23. Hello! Someone in my Myspace group shared this site with us so I
    came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this
    to my followers! Exceptional blog and great design and style.

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

  25. It is the best time to make some plans for the future and it
    is time to be happy. I’ve read this post and if I could I want to suggest you some
    interesting things or advice. Perhaps you could write
    next articles referring to this article. I wish to read even more things about it!

  26. Hi, I do believe this is a great web site.
    I stumbledupon it 😉 I’m going to come back once again since I saved as a favorite
    it. Money and freedom is the best way to change, may you be rich and continue to guide other people.

  27. This is the right webpage for anyone who really wants to find out about this topic.
    You realize a whole lot its almost hard to
    argue with you (not that I personally will need to…HaHa).

    You definitely put a brand new spin on a topic which has been written about
    for ages. Wonderful stuff, just excellent!

  28. Today, I went to the beachfront with my children. I found a sea shell and gave it
    to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.”
    She put the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  29. Howdy! Someone in my Myspace group shared this site with us so
    I came to give it a look. I’m definitely loving the information. I’m book-marking
    and will be tweeting this to my followers! Exceptional
    blog and wonderful style and design.

  30. I’m extremely pleased to find this website. I want to to thank you for your
    time for this wonderful read!! I definitely enjoyed every little bit of it and I have you bookmarked to look at new
    things on your website.

  31. I have been browsing online greater than three hours lately,
    but I never found any fascinating article like yours.
    It is pretty value enough for me. In my opinion, if all site owners and bloggers made just right content as you did,
    the net might be a lot more helpful than ever before.

  32. Woah! I’m really enjoying the template/theme of this blog.
    It’s simple, yet effective. A lot of times it’s very difficult to get that “perfect balance” between user friendliness and visual
    appeal. I must say that you’ve done a fantastic job with this.
    Additionally, the blog loads very quick for
    me on Firefox. Superb Blog!

  33. Good day very nice site!! Guy .. Excellent ..
    Superb .. I’ll bookmark your site and take the feeds
    also? I am glad to find numerous helpful info here in the submit, we’d like work out more
    techniques in this regard, thank you for sharing.

    . . . . .

  34. What’s up i am kavin, its my first time to commenting anywhere, when i read this piece of
    writing i thought i could also make comment due to this
    sensible paragraph.

  35. The crux of your writing whilst appearing reasonable originally, did not work properly with me personally after some time. Somewhere throughout the paragraphs you were able to make me a believer but just for a short while. I still have a problem with your leaps in assumptions and one might do well to fill in those gaps. In the event that you can accomplish that, I would undoubtedly be fascinated.

  36. My partner and I stumbled over here coming from a different page and
    thought I may as well check things out. I like what I see so now i am following you.
    Look forward to looking over your web page for a second time.

  37. Thanks for every other informative web site.
    Where else may I am getting that type of info written in such a perfect approach?
    I have a venture that I am simply now operating
    on, and I have been at the look out for such info.

  38. This is really interesting, You’re a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your fantastic post.
    Also, I’ve shared your site in my social networks!

  39. Hi there! I understand this is sort of off-topic but I had to ask.
    Does building a well-established website such as yours take a lot of work?
    I am completely new to running a blog but I do write in my journal
    every day. I’d like to start a blog so I can easily share my own experience and views online.
    Please let me know if you have any kind of suggestions or tips for
    brand new aspiring blog owners. Appreciate it!

  40. Hey There. I found your blog using msn. This is a really
    well written article. I will make sure to bookmark it and return to read more of your useful information. Thanks for the post.
    I will certainly comeback.

  41. Usually I do not read 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 amazed me. Thanks, very great article.

Leave a Reply

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