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