"Luogu" P3709 's string problem (Mo team algorithm)

Source: Internet
Author: User

Topic links

Chinese question ah ...

Look at the puzzle is to find the number of the most in the interval, so decisively understand a ... Mo's team is finished.

Sum[i] Indicates the number of occurrences of I, cnt[i] indicates that there are several occurrences of I, and then it's messed up ... Just fine.

  

#include <cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#include<cctype>#include<cmath>#defineMAXN 300000using namespaceStd;inlineLong LongRead () {Long Longnum=0, f=1; CharCh=GetChar ();  while(!isdigit (CH)) {        if(ch=='-') f=-1; CH=GetChar (); }     while(IsDigit (CH)) {num=num*Ten+ch-'0'; CH=GetChar (); }    returnnum*F;}intS[MAXN];intQ[MAXN];intD[MAXN];intANS[MAXN];structque{intX,y,id; BOOL operator< (ConstQue a)Const{        if(s[x]!=s[a.x])returns[x]<s[a.x]; returny<a.y; }}QUE[MAXN];intSUM[MAXN],CNT[MAXN];intMain () {intN=read (), m=read (); intsqt=sqrt (n);  for(intI=1; i<=n;++i) {Q[i]=d[i]=read (); S[i]= (I-1)/sqt+1; } sort (Q+1, q+n+1); intSize=unique (q+1, q+n+1)-q-1;  for(intI=1; i<=n;++i) D[i]=lower_bound (q+1, q+size+1, D[i])-Q;  for(intI=1; i<=m;++i) que[i]=(Que) {read (), read (), i}; Sort (que+1, que+m+1); intL=0, r=0, now=1; cnt[0]=1;  for(intI=1; i<=m;++i) {        intx=que[i].x,y=que[i].y;  while(r<y) {R++; int&o=Sum[d[r]]; if(now==o) now++; Cnt[o]--;    o++; cnt[o]++; }         while(r>y) {            int&o=Sum[d[r]]; Cnt[o]--;if(now==o&&cnt[o]==0) now--; o--; cnt[o]++; R--; }         while(l<x) {            int&o=Sum[d[l]]; Cnt[o]--;if(now==o&&cnt[o]==0) now--; o--; cnt[o]++; L++; }         while(l>x) {L--; int&o=Sum[d[l]]; Cnt[o]--;if(now==o) now++; o++; cnt[o]++; } Ans[que[i].id]=Now ; }     for(intI=1; i<=n;++i) printf ("%d\n",-Ans[i]); return 0;}

"Luogu" P3709 's string problem (Mo team algorithm)

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.