-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhotel_queries.cpp
55 lines (51 loc) · 1.11 KB
/
hotel_queries.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
#include <bits/stdc++.h>
#define endl "\n"
#define eat cin
#define moo cout
using namespace std;
struct segt{
int val, l, r, m;
segt *a, *b;
segt(int l, int r){
this->l = l, this->r = r;
m = (l + r) / 2;
if(l < r){
a = new segt(l, m), b = new segt(m+1, r);
}
val = 0;
}
void upd(int id, int v){
if(l > id || r < id) return;
if(l == r) val += v;
else{
a->upd(id, v), b->upd(id, v);
val = max(a->val, b->val);
}
}
int qry(int v){
if(val < v) return -1;
if(l == r) return l;
if(a->val >= v) return a->qry(v);
else return b->qry(v);
}
};
int N, M, h[200000];
segt *s;
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> N >> M;
for(int i = 0; i < N; i++){
eat >> h[i];
}
s = new segt(0, N-1);
for(int i = 0; i < N; i++){
s->upd(i, h[i]);
}
for(int i = 0; i < M; i++){
int r; eat >> r;
int id = s->qry(r);
moo << id+1 << " ";
if(id > -1) s->upd(id, -r);
}
moo << endl;
}