POJ 2796 Feel Good 【单调栈】
【题意】
给出n和a[1...n],求出一对l,r使得sum[l, r] * min[l, r]最大。
【题解】
往两边单调栈求出第一个比当前小的数的位置。
然后随便做啦,O(n)
# include <stdio.h> # include <iostream> # include <string.h> using namespace std; int n, a[100100], last[100100], next[100100]; int st[100100], stn=0; int stw[100100], l, r; long long s[100100], maxx=-99999999; int main() { scanf("%d", &n); for (int i=1; i<=n; ++i) { scanf("%d", &a[i]); s[i] = s[i-1] + a[i]; } for (int i=1; i<=n; ++i) { if(a[i] > st[stn]) { st[++stn] = a[i]; last[i] = stw[stn-1]; stw[stn] = i; } else { while(a[i] <= st[stn] && stn != 0) --stn; if(stn == 0) last[i] = 0; else last[i] = stw[stn]; st[++stn] = a[i]; stw[stn] = i; } } stn = 0; memset(st, 0, sizeof(st)); memset(stw, 0, sizeof(stw)); for (int i=n; i>=1; --i) { if(a[i] > st[stn]) { st[++stn] = a[i]; next[i] = stw[stn-1]; stw[stn] = i; } else { while(a[i] <= st[stn] && stn != 0) --stn; if(stn == 0) next[i] = n+1; else next[i] = stw[stn]; st[++stn] = a[i]; stw[stn] = i; } } for (int i=1; i<=n; ++i) { //printf("%d %d\n", last[i], next[i]); long long t = (long long)a[i] * (s[next[i]-1] - s[last[i]]); if(t>maxx) { maxx=t; l=last[i]+1; r=next[i]-1; } } cout << maxx << endl; cout << l << ' ' << r << endl; return 0; }
2022年9月20日 22:40
PUC Question Paper 2023 for Kar 1st & 2nd PUC Biology Model Paper 2023 Pdf Download with Answer Solutions for Theory, Objective type Multiple Choice Questions for Kannada Medium & English Medium students with important Questions. Kar PUC Biology Question Paper Biology is one of the most important subjects to Pre University Education (PUE) 1st and 2nd year Science stream students, and biology is a related subject of natural science, every student of PUC I & PUC II Science group Kannada medium and English medium student can download Karnataka 1st & 2nd Year PUC Biology Model Paper 2023.
2024年1月10日 13:50
Pavzi.com provides all the news about Gadgets, the Economy, Technology, Business, Finance and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us. pavzi.com Our site is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.
2024年12月11日 17:04
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
2024年12月11日 18:41
Start being true conservatives? You menot, you can speak out against the drug war without insulting educated progressives with your silly beliefs.
2024年12月11日 18:45
Hello ! I am a student writing a report on the subject of your post.Your article is an article with all the content and topics. I've ever wanted . Thanks to this, it will be of great help to the report I am preparing now.Thanks for your hard work. And if you have time, please visit my site as well. is one very interesting post. like the way you write and I will bookmark your blog to my favorites. Strong blog. I acquired various nice information
2024年12月11日 18:45
Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I’m more of a visual learner,I found that to be more helpful well let me know how it turns out.
2024年12月11日 18:46
The anti-marijuana crowd likes to poroking marijuana makes you a lazy underachiever whose brain cells are all destroyed, or it makes you a drug-crazed "Reefer Madness" lunatic/terrorist/Super-Genius. But it can't be both.
2024年12月11日 18:46
whoah this blog is great i like reading your articles. Keep up the great paintings! You know, a lot of individuals are looking around for this info, you can aid them greatly
2024年12月11日 18:47
IceCream Screen Recorder Crack is one of the high-quality software on this planet with the reason of assisting the consumer in taking pictures of the som
2024年12月11日 18:47
Acknowledges for paper such a beneficial composition, I stumbled beside your blog besides decipher a limited announce. I want your technique of inscription..
2024年12月11日 18:48
Recently, I have commenced a blog the info you give on this site has encouraged and benefited me hugely. Thanks for all of your time & work.
2024年12月11日 18:49
Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you
2024年12月11日 18:49
whoah this blog is great i like reading your articles. Keep up the great paintings! You know, a lot of individuals are looking around for this info, you can aid them greatly
2024年12月11日 18:50
Great blog here! Additionally your website quite a bit up very fast! What web host are you the use of? Can I am getting your affiliate hyperlink on your host? I desire my web site loaded up as quickly as yours lol
2024年12月11日 21:31
I would like to thnkx for the efforts you have put in writing this site. I’m hoping the same high-grade site post from you in the upcoming as well. In fact your creative writing abilities has inspired me to get my own site now. Really the blogging is spreading its wings fast. Your write up is a great example of it. rentacarkosovo
2024年12月11日 21:32
Hello! I just now wish to provide a huge thumbs up for the great information you could have here during this post. We are coming back to your website for further soon
2024年12月11日 21:33
M3M Mansion is strategically located in Sector 65, Gurgaon, providing residents with excellent connectivity to major landmarks and business hubs. The proximity to Golf Course Extension Road ensures seamless access to NH-8, Sohna Road, and other important arterial roads. The area is well-served by public transportation, making commuting a breeze for the residents. M3M Mansion Gurgaon stands out with its contemporary architecture and exquisite design. The project boasts spacious and well-ventilated apartments that are thoughtfully crafted to offer a perfect blend of aesthetics and functionality.
2024年12月11日 21:33
Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.Truly quite intriguing post. I was searching for this sort of data and delighted in perusing this one. Continue posting. Much obliged for sharing
2024年12月11日 21:34
This web-site is often a walk-through its the internet it suited you about this and didn’t know who to question. Glimpse here, and you’ll absolutely discover it.
2024年12月11日 21:34
i find issues i have been looking for. You have got a clever yet attractive way of writing. I am glad i found this web web site, i could not locate any information in this count number prior to. Additionally perform a domain and if you are ever inquisitive about performing some traveler writing for me if possible sense loose to let me recognize, im constantly search for human beings to check out my web site. I appreciate the entirety you have brought to my knowledge base. Admiring the effort and time you placed into your weblog and particular statistics you offer. Thanks. Truly i revel in your site with effective and useful statistics. It's miles blanketed very satisfactory post with quite a few our assets. Thanks for percentage. I revel in this put up
2024年12月11日 21:35
Those pieces of junk actually said, in the Angel Raich case, that even if your only alternatives are to use cannabis or to die, there is no constitutional right for you to use cannabis. They are really far gone fascists to make a claim like that. Their decision ranks in infamy right up there with the Dred Scott slavery case and similar findings regarding Native Americans, that neither group were persons, as defined by ye olde Constitution. They are basically saying that if you need medicinal cannabis you are not a person, because obviously people have the right to use the best medicine available to treat a serious or very serious medical problem.
2024年12月11日 21:35
Seriously, no one disrespects cops more than I do, but even I'm not falling for this one. The drug warriors involved in this exercise cannot possibly be stupid enough to believe this scenario. The thing about drug warriors is that they don't mind acting stupid if it will further their cause. Since they can no longer even pretend that pot is dangerous, they have to pretend the pot USERS are. And pretend that they're actually going to protect the public. Marijuana terrorism. Boy, this is even better than exploding meth labs.
2024年12月11日 21:35
Increase In Stamina. 8- Good Remedy For Premature Ejaculation. 9- No Side Effects, Natural & Safe. 10- Improvement In Self-Estream. 11- Increased Endurance,
2024年12月11日 21:36
I would like to thnkx for the efforts you have put in writing this site. I’m hoping the same high-grade site post from you in the upcoming as well. In fact your creative writing abilities has inspired me to get my own site now. Really the blogging is spreading its wings fast. Your write up is a great example of it. rentacarkosovo
2024年12月11日 21:37
Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I’m more of a visual learner,I found that to be more helpful well let me know how it turns out.