求大佬指导

P2681 众数

希望更丰富的展现?使用Markdown
by A_Đark_Horcrux @ 2018-09-15 22:14:35


``` #include<iostream> using namespace std; int a[1010]; struct node { int a,s; }b[1010]; int work(int a,int b) { if(a<=b) return a; else return b; } int main() { int n,m; bool flag; cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) { cin>>flag; if(flag) { int x,y; cin>>x>>y; a[x]=y; } else{ int x,y; cin>>x>>y; int n2=1,find=0,n1=a[x],nmax=-1,i2=1; b[1].a=a[x];b[1].s=1; for(int j=x+1;j<=y;j++) { find=0; if(a[j]!=n1){ n1=a[j]; for(int i1=1;i1<=i2;i1++) { if(n1==b[i1].a) {n2=i1,find=1;break; } } if(find) b[n2].s++; else i2++,b[i2].a=a[j],b[i2].s=1; } else b[i2].s++; } if(x==y) cout<<a[x]; else{ for(int j=1;j<=i2;j++){ if(nmax<b[j].s) nmax=b[j].s,n1=b[j].a; if(nmax==b[j].s) { if(n1>b[j].a) nmax=b[j].s,n1=b[j].a; } } cout<<n1<<endl; } } } return 0; } ```
by Do_if @ 2018-09-15 22:15:08


@[Gavin帅](/space/show?uid=54372) 唔………………
by Do_if @ 2018-09-15 22:15:36


|