func_code_string: #include <bits/stdc++.h>   using namespace std;   int sum[101000 << 2], lsum[101000 << 2], rsum[101000 << 2], lazy[101000 << 2];   int L[105];   int ans[105];   int max(int a, int b) { return a > b ? a : b; }   void pushup(int rt, int len) {     sum[rt] = max(sum[rt << 1], sum[rt << 1 | 1]);     sum[rt] = max(sum[rt], rsum[rt << 1] + lsum[rt << 1 | 1]);     lsum[rt] = lsum[rt << 1];     if (lsum[rt] == len - (len >> 1)) lsum[rt] += lsum[rt << 1 | 1];     rsum[rt] = rsum[rt << 1 | 1];     if (rsum[rt] == (len >> 1)) rsum[rt] += rsum[rt << 1];   }   void pushdown(int rt, int len) {     lazy[rt << 1] = lazy[rt << 1 | 1] = lazy[rt];     if (lazy[rt] == 0) {       sum[rt << 1] = sum[rt << 1 | 1] = 0;       lsum[rt << 1] = lsum[rt << 1 | 1] = 0;       rsum[rt << 1] = rsum[rt << 1 | 1] = 0;     } else {       sum[rt << 1] = lsum[rt << 1] = rsum[rt << 1] = len - (len >> 1);       sum[rt << 1 | 1] = lsum[rt << 1 | 1] = rsum[rt << 1 | 1] = len >> 1;     }     lazy[rt] = -1;   }   void update(int l, int r, int rt, int L, int R, int val) {     if (l >= L && r <= R) {       sum[rt] = val * (r - l + 1);       lsum[rt] = val * (r - l + 1);       rsum[rt] = val * (r - l + 1);       lazy[rt] = val;       return;     }     if (lazy[rt] != -1) {       pushdown(rt, r - l + 1);     }     int m = (l + r) >> 1;     if (L <= m) update(l, m, rt << 1, L, R, val);     if (R > m) update(m + 1, r, rt << 1 | 1, L, R, val);     pushup(rt, r - l + 1);   }   int query(int l, int r, int rt, int L) {     if (sum[rt] < L) return -1;     if (lazy[rt] != -1) {       pushdown(rt, r - l + 1);     }     int m = (l + r) >> 1;     if (sum[rt << 1] >= L) {       return query(l, m, rt << 1, L);     } else if (rsum[rt << 1] + lsum[rt << 1 | 1] >= L) {       return m - rsum[rt << 1] + 1;     }     return query(m + 1, r, rt << 1 | 1, L);   }   void print(int l, int r, int rt) {     printf(           l = %d r = %d sum[rt] = %d , lsum[rt] = %d , rsum[rt] = %d lazy[rt] =            %d  n ,         l, r, sum[rt], lsum[rt], rsum[rt], lazy[rt]);     if (l == r) return;     int m = (l + r) >> 1;     print(l, m, rt << 1);     print(m + 1, r, rt << 1 | 1);   }   int main() {     int n, b, f;     while (scanf( %d%d%d , &n, &b, &f) != EOF) {       memset(lazy, -1, sizeof(lazy));       n += b + f;       update(1, n, 1, 1, n, 1);       int k, i;       scanf( %d , &k);       for (i = 1; i <= k; i++) {         int t;         scanf( %d%d , &t, &L[i]);         if (t == 1) {           int pos = query(1, n, 1, L[i] + b + f);           if (pos == -1) {             printf( -1 n );             ans[i] = -1;           } else {             printf( %d n , pos - 1);             update(1, n, 1, pos + b, pos + b + L[i] - 1, 0);             ans[i] = pos + b;           }         } else {           if (ans[L[i]] == -1) continue;           update(1, n, 1, ans[L[i]], ans[L[i]] + L[L[i]] - 1, 1);         }       }     }     return 0;   }   