#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 200000 + 7;
struct node {
int left, right;
int val;
} str[maxn*10];
int w, h, n;
int ans = -1;
void BuildTree(int root, int left, int right) {
int mid = (left + right) / 2;
str[root].left = left;
str[root].right = right;
str[root].val = w;
if(left == right) return ;
BuildTree((root << 1), left, mid);
BuildTree((root << 1) + 1, mid + 1, right);
}
bool Query(int root, int pos) {
if(str[root].val < pos) return false;
if(str[root].left == str[root].right) {
if(str[root].val >= pos) {
ans = str[root].left;
str[root].val -= pos;
return true; //找到解就退出后面的都不用找了
}
return false;
}
if(Query(root * 2, pos)) return true; ///<span style="font-family: Arial, Helvetica, sans-serif;">找到解就退出后面的都不用找了</span>
if(Query(root * 2 + 1, pos)) return true;
if(str[root<<1].val > str[(root<<1)+1].val) str[root].val = str[root<<1].val;
else str[root].val = str[(root<<1)+1].val;
return false;
}
int main() {
while(scanf("%d%d%d", &h, &w, &n) != EOF) {
if(h > n) h = n + 7;
BuildTree(1, 1, h);
int wi;
for(int i = 0; i < n; ++i) {
ans = -1;
scanf("%d", &wi);
Query(1, wi);
printf("%d\n", ans);
}
}
return 0;
}//线段树
hdu2795
最新推荐文章于 2021-10-15 21:28:06 发布