| ||||||||||
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 |
WA了N次,跪求大牛指点迷津#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define maxN 263000 int st[maxN * 2]; int ans[maxN]; int n, M; int find(int i, int l, int r, int id){ int child, blank, mid; for(; id<M; id=child){ st[id]++; mid=(l+r)>>1; child=id<<1; blank=mid-l+1-st[id<<1]; if(i<blank) r=mid; else{ i-=blank; child++; l=mid+1; } } st[id]++; return id-M; } void getm(){ for(int i=1; i<0xfffffff; i++) if(i>n) {M=i; break;} } struct node{ int p, v; }line[maxN]; int main(){ int pos; while(scanf("%d", &n)==1){ getm(); for(int i=n-1; i>=0; i--){ scanf("%d %d", &line[i].p, &line[i].v); } memset(st, 0, sizeof(st)); for(int i=0; i<n; i++){ pos=find(line[i].p, 0, M-1, 1); ans[pos]=line[i].v; } for(int i=0; i<n-1; i++) printf("%d ", ans[i]); printf("%d\n", ans[n-1]); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator