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 |
Re:都做到这个份上了,怎么还超时In Reply To:牛人看下为何超时!!!!!!!! Posted by:lijingwei at 2010-07-04 11:21:39 #include<iostream> #include<algorithm> using namespace std; struct In { int x; int id; }s[100015]; int cmp(const void *a , const void *b) { struct In *c=(In *)a; struct In *d = (In *)b; return c->x-d->x; } int main() { int m,n; int a,b,c,i; cin>>n>>m; for(i=0;i<n;i++) { scanf("%d",&s[i].x); s[i].id=i; } qsort(s,n,sizeof(s[0]),cmp);//只用作一次快排,而不是m次 while(m--) { scanf("%d%d%d",&a,&b,&c); for(i=0;i<n;i++) { if(s[i].id>=a-1&&s[i].id<=b-1) c--; if(c==0)//数到0,则找到该数 break; } printf("%d\n",s[i].x); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator