hdu2795(線段樹單點修改)
阿新 • • 發佈:2018-12-03
/**/ #include <cstdio> #include <cstring> #include <cmath> #include <cctype> #include <iostream> #include <algorithm> #include <map> #include <set> #include <vector> #include <string> #include <stack> #include <queue> typedef long long LL; using namespace std; int h, w, n; int t[4 * 200005]; void build(int p, int l, int r){ t[p] = w; if(l == r) return ; int mid = (l + r) >> 1; build(p << 1, l, mid); build(p << 1 | 1, mid + 1, r); } int modify(int p, int l, int r, int x){ if(l == r){ t[p] -= x; return l; } int mid = (l + r) >> 1; int ans = (t[p << 1] >= x) ? modify(p << 1, l, mid, x) : modify(p << 1 | 1, mid + 1, r, x); t[p] = max(t[p << 1], t[p << 1 | 1]); return ans; } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); while(scanf("%d %d %d", &h, &w, &n) == 3){ if(h > n) h = n; build(1, 1, h); int len; for (int i = 1; i <= n; i++){ scanf("%d", &len); if(t[1] < len){ printf("-1\n"); }else{ printf("%d\n", modify(1, 1, h, len)); } } } return 0; } /**/