forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3635 - Cinema in Akiba.cpp
58 lines (40 loc) · 1.02 KB
/
3635 - Cinema in Akiba.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <cstdio>
#include <cstring>
using namespace std;
#define MAXN 50000
int bit[MAXN + 1];
void update(int idx){
for(int x = idx;x <= MAXN;x += x & -x)
++bit[x];
}
int query(int idx){
int ret = 0;
for(int x = idx;x > 0;x -= x & -x)
ret += bit[x];
return ret;
}
int main(){
int N,Q,lo,hi,mi,ans[MAXN];
while(scanf("%d",&N) == 1){
memset(bit,0,sizeof bit);
for(int i = 1,a;i <= N;++i){
scanf("%d",&a);
lo = 1; hi = N;
while(lo < hi){
mi = (lo + hi) >> 1;
if(mi - query(mi) < a) lo = mi + 1;
else hi = mi;
}
ans[i] = lo;
update(lo);
}
scanf("%d",&Q);
for(int i = 0,x;i < Q;++i){
scanf("%d",&x);
if(i) putchar(' ');
printf("%d",ans[x]);
}
printf("\n");
}
return 0;
}