Why my program still WA?Please help me!Thank you! #include<stdio.h> #include<string.h> #define max 15001 int n,x,yy,y,s,num,len,leng,note[max][2],total[max]; void work() { int i,t; while((s<len)&&(note[s][1]<x)){note[s][0]+=num;s++;} i=s-1;num++; if((i<0)&&(note[s][1]!=x)){note[leng][0]=num;total[num-1]++;note [leng][1]=x;leng++;return;} if(note[s][1]==x) {t=note[s][0]-1;note[s][0]+=num;total[note[s][0]-1]++;s++;} else {t=note[i][0]+num;note[leng][0]=t;total[t-1]++;note[leng][1] =x;leng++;} } void add() { int i; for(i=s;i<len;i++) {note[i][0]+=num;} } void sort() { int i,j,k,n0,n1; i=0; for(j=len;j<leng;j++) { n0=note[j][0];n1=note[j][1]; while(note[i][1]<n1)i++; for(k=len;k>i;k--) {note[k][0]=note[k-1][0];note[k][1]=note[k-1][1];} note[i][0]=n0;note[i][1]=n1; i++;len++; } } void out() { int i; for(i=0;i<n;i++)printf("%d\n",total[i]); } void main() { int i; memset(note,0,sizeof(note)); memset(total,0,sizeof(total)); scanf("%d",&n);yy=len=leng=num=0; for(i=0;i<n;i++) { scanf("%d%d",&x,&y); if(y!=yy){yy=y;add();sort();len=leng;s=num=0;} work(); } len=leng; out(); } Sorry,I've Ac now > #include<stdio.h> > #include<string.h> > > #define max 15001 > > int n,x,yy,y,s,num,len,leng,note[max][2],total[max]; > > void work() > { > int i,t; > while((s<len)&&(note[s][1]<x)){note[s][0]+=num;s++;} > i=s-1;num++; > if((i<0)&&(note[s][1]!=x)){note[leng][0]=num;total[num-1]++;note > [leng][1]=x;leng++;return;} > if(note[s][1]==x) > {t=note[s][0]-1;note[s][0]+=num;total[note[s][0]-1]++;s++;} > else > {t=note[i][0]+num;note[leng][0]=t;total[t-1]++;note[leng][1] > =x;leng++;} > } > > void add() > { > int i; > for(i=s;i<len;i++) > {note[i][0]+=num;} > } > > void sort() > { > int i,j,k,n0,n1; > i=0; > for(j=len;j<leng;j++) > { > n0=note[j][0];n1=note[j][1]; > while(note[i][1]<n1)i++; > for(k=len;k>i;k--) > {note[k][0]=note[k-1][0];note[k][1]=note[k-1][1];} > note[i][0]=n0;note[i][1]=n1; > i++;len++; > } > } > > void out() > { > int i; > for(i=0;i<n;i++)printf("%d\n",total[i]); > } > > void main() > { > int i; > memset(note,0,sizeof(note)); > memset(total,0,sizeof(total)); > scanf("%d",&n);yy=len=leng=num=0; > for(i=0;i<n;i++) > { > scanf("%d%d",&x,&y); > if(y!=yy){yy=y;add();sort();len=leng;s=num=0;} > work(); > } > len=leng; > out(); > } |