-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19646.cpp
More file actions
51 lines (39 loc) · 941 Bytes
/
19646.cpp
File metadata and controls
51 lines (39 loc) · 941 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 200050
const int ST = 1<<18;
int N,w[MAXN],p[MAXN],seg[ST*2];
void build(){
for(int i=0 ; i<N ; i++){
seg[ST+i] = w[i];
}
for(int i=ST-1 ; i>0 ; i--){
seg[i] = seg[i*2]+seg[i*2+1];
}
}
void update(int n, int val){
seg[n] = val;
for(int i=n/2 ; i>0 ; i/=2) seg[i] = seg[i*2]+seg[i*2+1];
}
int findNum(int n, int pos){
if(n>=ST) return n-ST+1;
int left_val = seg[n*2];
if(pos > left_val) return findNum(n*2+1, pos-left_val);
return findNum(n*2,pos);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> N;
for(int i=0 ; i<N ; i++) cin >> w[i];
for(int i=0 ; i<N ; i++) cin >> p[i];
build();
for(int i=0 ; i<N ; i++){
int a = findNum(1,p[i]);
update(ST+a-1, 0);
cout << a <<" ";
}
}