SOS

UVA501 Black Box

@[唐路凌最可爱](/space/show?uid=61940) %%%
by 大略 @ 2019-10-10 17:13:55


@[大略](/space/show?uid=66385) 别% 帮我改一下吧
by Alviss_lky @ 2019-10-10 17:16:34


@[唐路凌最可爱](/space/show?uid=61940) UVA每组数据之间有换行,最后一组没有,注意下格式
by 大略 @ 2019-10-10 17:23:16


@[唐路凌最可爱](/space/show?uid=61940) ```cpp #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define init(x) memset(x,0,sizeof(x)) using namespace std; int n,m,tot,root; int l[200010],r[200010],num[200010],k[200010],s[200010],rep[200010]; int nu[200010],g[200010]; inline void mt(int p) { s[p]=s[l[p]]+s[r[p]]+1; } inline void clear() { n=0; m=0; tot=0; root=0; init(l); init(r); init(num); init(k); init(s); init(rep); init(nu); init(g); } void lturn(int &p) { int t=r[p]; r[p]=l[t]; l[t]=p; mt(p); mt(t); p=t; } void rturn(int &p) { int t=l[p]; l[p]=r[t]; r[t]=p; mt(p); mt(t); p=t; } void insert(int &p,int x) { if(!p) { p=++tot; num[p]=x; k[p]=rand(); s[p]=1; return; } s[p]++; if(x<num[p]) { insert(l[p],x); if(k[l[p]]>k[p]) rturn(p); } else { insert(r[p],x); if(k[r[p]]>k[p]) lturn(p); } } int kth(int x) { int p=root,ans=s[l[root]]+1; while(p) { if(x==ans) return num[p]; else if(x>ans) { p=r[p]; ans+=s[l[p]]+1; } else { p=l[p]; ans-=s[r[p]]+1; } } return 0; } int main() { int T; scanf("%d",&T); while(T--) { clear(); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",nu+i); for(int i=1;i<=m;i++) scanf("%d",g+i); int j=1,t=0; for(int i=1;i<=n;i++) { insert(root,nu[i]); while(g[j]==i) { printf("%d\n",kth(++t)); j++; } } if(T!=0) printf("\n"); } return 0; } ```
by 大略 @ 2019-10-10 17:23:29


@[唐路凌最可爱](/space/show?uid=61940) 收费`1000000000000000RMB`
by 大略 @ 2019-10-10 17:24:34


@[大略](/space/show?uid=66385) 去你的
by Alviss_lky @ 2019-10-10 17:26:09


如果你%10000我可以给你
by Alviss_lky @ 2019-10-10 17:26:22


@[beargeng](/space/show?uid=103202) 好像还欠我`10000000000RMB` @[wifi见狗怂](/space/show?uid=86070) 欠我`(1e14+1e13+5*1e12+500)的100次方 RMB`
by 大略 @ 2019-10-10 17:26:26


@[唐路凌最可爱](/space/show?uid=61940) 过了吗?
by 大略 @ 2019-10-10 17:26:40


@[大略](/space/show?uid=66385) 过了
by Alviss_lky @ 2019-10-10 17:26:58


| 下一页