#include <cstdio>
#include <algorithm>
using namespace std;
/*大佬是先放公告,再比较高度。我的想法是先比较高度,再看能不能放。代码是大佬的*/
const int kMax = 2e5 + 10;
struct node {
int l, r, max;
} tree[kMax << 2];
int h, w, n;
void pushup(int p) {
tree[p].max = max(tree[p << 1].max, tree[p << 1 | 1].max);
}
void build(int p, int l, int r) {
tree[p].l = l;
tree[p].r = r;
if(l == r) {
tree[p].max = w;
return;
}
int m = (l + r) >> 1;
build(p << 1, l, m);
build(p << 1 | 1, m + 1, r);
pushup(p);
}
void modify(int p, int l, int r, int val) {
if(tree[p].l == tree[p].r && tree[p].max >= val) {
tree[p].max -= val;
printf("%d\n", tree[p].l > h ? -1 : tree[p].l);
return;
}
if(val <= tree[p << 1].max) modify(p << 1, l, r, val);
else modify(p << 1 | 1, l, r, val);
pushup(p);
}
int main() {
int t;
scanf("%d%d%d", &h, &w, &n);
build(1, 1, n);
for(int i = 0;i < n;++ i) {
scanf("%d", &t);
modify(1, 1, n, t);
}
return 0;
}
线段树之公告板
最新推荐文章于 2022-01-31 16:55:51 发布