Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
for循环里面为什么不sort?In Reply To:不好意思,改了一点小错误,不过现在还是WA ,继续请大家帮忙!!!!!(内附代码) Posted by:elf788544 at 2006-02-28 18:33:27 > 不好意思,改了一点小错误,不过现在还是WA ,继续请大家帮忙!!!!! > #include <stdio.h> > #include <vector> > #include <algorithm> > using namespace std; > #define MAXN 100001 > vector<int>sp; > int a[MAXN]; > int res[50001]; > struct seg > { > int s,t; > int k; > int ind; > }se[50001]; > bool cmp(seg aa,seg bb) > { > return aa.s<bb.s || aa.s==bb.s && aa.t<bb.t; > } > void vpop(int x) > { > int sta=0,end=sp.size()-1,mid=0; > while(sta<=end) > { > mid=(sta+end)/2; > if(x>sp[mid]) sta=mid+1; > else if(x<sp[mid]) end=mid-1; > else > { > sp.erase(sp.begin()+mid); > return; > } > } > } > void vpush(int x) > { > int sta=0,end=sp.size()-1,mid=0; > while(sta<=end) > { > mid=(sta+end)/2; > if(x>sp[mid]) sta=mid+1; > else if(x<sp[mid]) end=mid-1; > else > { > sp.insert(sp.begin()+mid+1,x); > return; > } > } > } > void out(void) > { > register int i; > for(i=0;i<sp.size();i++) > printf("%2d",sp[i]); > printf("\n"); > } > int main() > { > register int i,j; > int n,m; > scanf("%d%d",&n,&m); > for(i=1;i<=n;i++) > scanf("%d",a+i); > for(i=0;i<m;i++) > { > scanf("%d%d%d",&se[i].s,&se[i].t,&se[i].k); > se[i].ind=i; > } > sort(se,se+m,cmp); > for(i=se[0].s;i<=se[0].t;i++) > sp.push_back(a[i]); > sort(sp.begin(),sp.end()); > res[se[0].ind]=sp[se[0].k-1]; > //(); > for(i=1;i<m;i++) > { > if(se[i-1].t<se[i].s) > { > for(j=se[i-1].s;j<=se[i-1].t;j++) > { > vpop(a[j]); > //out(); > } > for(j=se[i].s;j<=se[i].t;j++) > { > vpush(a[j]); > //out(); > } > } > else > { > for(j=se[i-1].s;j<se[i].s;j++) > { > vpop(a[j]); > //out(); > } > for(j=se[i-1].t+1;j<=se[i].t;j++) > { > vpush(a[j]); > //out(); > } > } > res[se[i].ind]=sp[se[i].k-1]; > } > for(i=0;i<m;i++) > printf("%d\n",res[i]); > return 0; > } > > > > > > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator