At the beginning, I felt that this question was a two-dimensional line segment tree. Then I analyzed it as if it was not, that is, the position of the maximum value of the interval. I felt like a part of the previous reverse order number, and the query was updated; this question is a combination of query and update. However, I won't write code for this weak dish, and then I decided to refer to the template of HH shenniu; orz... All kinds of weak and casual, just learning the line segment tree, you have to work hard in the future. For the first time so late, you are still writing code, orz .. Only me will stay up late...
Well, we will be here for a while, or else we will be suspended. I have seen a lot of news on the Internet over the past few days. I don't want this to happen to me...
Cherish life and stay away from code
#include <cstdlib>#include <iostream>#include<cstdio>#include<cmath> #include<algorithm>using namespace std;#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1 | 1const int N=200005;int num[N<<2],h,w,n;void PushUp(int rt){ num[rt]=max(num[rt<<1],num[rt<<1|1]); } void build(int l,int r,int rt){ num[rt]=w; if(l==r)return; int mid=(l+r)>>1; build(lson); build(rson);}int Query(int val,int l,int r,int rt){ if(l==r) { num[rt] -= val; return l; } int mid = (l+r) >> 1 ; int res = num[rt<<1] >= val ? Query(val,lson) : Query(val,rson) ; PushUp(rt); return res;}int main(int argc, char *argv[]){ int val; while(~scanf("%d%d%d",&h,&w,&n)) { if(h>n)h=n; build(1,h,1); while(n--) { scanf("%d",&val); if(num[1]<val)printf("-1\n"); else{ printf("%d\n",Query(val,1,h,1)); } } } return EXIT_SUCCESS;}