裸线段树,水题1A之。
/*#########################################################################
# File Name: c.cpp
# Author: CaoLei
# Created Time: 2015/7/13 14:15:38
#########################################################################*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)<(y))?(x):(y))
#define N 500010
#define pi acos(-1.0)
#define inf 100000000
typedef long long ll;
typedef unsigned long long ull;
struct tre{
int l, r;
int len;
}tree[200000];
int ans[50010];
void build(int root, int l, int r){
tree[root].l = l;
tree[root].r = r;
tree[root].len = r - l + 1;
if (l == r) return;
build(root*2, l, (l + r) / 2);
build(root*2+1, (l + r) / 2 + 1, r);
}
int query(int root, int k){
tree[root].len--;
if (tree[root].l == tree[root].r) return tree[root].l;
else if (k>tree[root*2].len)
return query(root *2 + 1, k - tree[root << 1].len);
else return query(root * 2, k);
}
int main(){
//freopen("in.txt", "r", stdin);
int n, m;
int tmp;
while (~scanf("%d", &n)){
memset(tree, 0, sizeof(tree));
memset(ans, 0, sizeof(ans));
build(1, 1, n);
for (int i = 1; i <= n; i++){
scanf("%d", &tmp);
ans[i] = query(1, tmp);
// printf("%d ", ans[i]);
}
//printf("\n");
scanf("%d", &m);
for (int i = 1; i < m; i++){
scanf("%d", &tmp);
printf("%d ", ans[tmp]);
}
scanf("%d",&tmp);
printf("%d\n",ans[tmp]);
}
return 0;
}