"Luo gu P1371" Noi shenyuandan

Source: Internet
Author: User

Do not consider insert

The number of NOI can be recursive by O (n):

Sum_noi<--sum_no<--sum_n

Consider insert:

The first preprocessing for each n, the following o and I each have how many

N: Apparently inserted at the front

I: The last Side

O: Enumerate breakpoints, preceded by N, I, take Max

1#include <cstdio>2#include <cstring>3 using namespacestd;4 #definell Long Long5 Const intL=100100;6 intN,nn,ii,oo;7 ll Ans,sum_n,sum_no,sum_noi;8 CharS[l];9 structfax{Ten     intLoc,o,i;//Loc??? °μ? O£??? Oóμ? I One }n[l]; A structfbx{ -     intLoc,i;//Loc?? Oóμ? I - }o[l]; the ll Max (ll X,ll y) { -     returnX>y?x:y; - } - voidAddn () { +ll n0=0; -      for(intj=1; j<=oo;j++) +n0+=o[j].i; AAns=max (ans,sum_noi+n0); at } - voidAddi () { -ll ooo,i0=0; -      for(intI=1; i<=nn;i++){ -ooo=N[I].O; -i0+=oo-ooo; in     } -Ans=max (ans,sum_noi+i0); to } + voidAddO () { -ll o0=0; the      for(intj=1; j<=nn;j++) *O0=max (O0, (LL) j*n[j].i); $Ans=max (ans,sum_noi+o0);Panax Notoginseng } - intMain () { thesum_n=sum_no=sum_noi=ii=oo=nn=ans=0; +scanf"%d",&n); Ascanf"%s", s); the      for(intI=0; i<n;i++){ +         if(s[i]=='N'){ -nn++; $N[nn].loc=i; $n[nn].o=Oo; -N[nn].i=II; -sum_n++; the         } -         if(s[i]=='O'){Wuyioo++; theO[oo].loc=i; -O[oo].i=II; Wusum_no+=Sum_n; -         } About         if(s[i]=='I'){ $ii++; -sum_noi+=Sum_no; -         } -     } A      for(intj=1; j<=nn;j++) +n[j].i=ii-n[j].i; the      for(intj=1; j<=oo;j++) -o[j].i=ii-o[j].i; $ Addn (); the AddO (); the Addi (); theprintf"%lld", ans); the     return 0; -}
STD

"Luo gu P1371" Noi shenyuandan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.