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)