#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 * 2 + 10;
int h, w, n, date[maxn], segTree[maxn<<2];
void pushup(int root) {
segTree[root] = max(segTree[root<<1], segTree[root<<1|1]);
}
void build(int L, int R, int root) {
if (L == R) {
segTree[root] = w;
return;
}
int mid = (L + R)>>1;
build(L, mid, root<<1);
build(mid + 1, R, root<<1|1);
pushup(root);
}
int query(int L, int R, int root, int val) {
if (L == R) {
segTree[root] -= val;
return L;
}
int mid = (L + R)>>1;
int ans = (segTree[root<<1] >= val) ? query(L, mid, root<<1, val) : query(mid + 1, R, root<<1|1, val);
pushup(root);
return ans;
}
int main()
{
while (scanf("%d %d %d", &h, &w, &n) == 3) {
if (h > n) {
h = n;
}
build(1, h, 1);
for (int i = 1; i <= n; i++) {
int temp; scanf("%d", &temp);
if (segTree[1] < temp) {
printf("-1\n");
}
else {
printf("%d\n", query(1, h, 1, temp));
}
}
}
return 0;
}
HDU 2795 Billboard——特殊查询的线段树
最新推荐文章于 2019-11-19 16:39:45 发布