#include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; template using GPQ = priority_queue, greater>; using P = pair; using P2 = pair; template ostream& operator<<(ostream& os, vector v) { os << "{"; for (int i = 0; i < v.size(); ++i) { if(i) os << ", "; os << v[i]; } return os << "}"; } template ostream& operator<<(ostream& os, pair p) { return os << "{" << p.first << ", " << p.second << "}"; } int main() { int n, k1, k2; cin >> n >> k1 >> k2; vector v(n); if(k1 < k2){ int l = k1-1, r = k2-1, c = 0; while(0 <= l || r < n){ if(0 <= l) v[l--] = c++; if(r < n) v[r++] = c++; } }else { int l = k2-1, r = k1-1, c = 0; while(0 <= l || r < n){ if(r < n) v[r++] = c++; if(0 <= l) v[l--] = c++; } } auto cmp = [&](P x, P y){ if(x.first != y.first) return x.first < y.first; else return v[x.second] < v[y.second]; }; set s(cmp); for (int i = 0; i < n; ++i) { s.emplace(0, i); // 0 : empty 1 : adjacent 2 : not empty } vector data(n, 0); int q; cin >> q; auto update = [&](int i, int j){ if(j == 0){ if(i != 0 && data[i-1] == 2) j = 1; if(i != n-1 && data[i+1] == 2) j = 1; } if(data[i] == j) return; if(data[i] != 2) s.erase({data[i], i}); if(j != 2) s.emplace(j, i); data[i] = j; if(j == 2){ if(i != 0 && !data[i-1]){ s.erase({data[i-1], i-1}); s.emplace(1, i-1); data[i-1] = 1; } if(i != n-1 && !data[i+1]){ s.erase({data[i+1], i+1}); s.emplace(1, i+1); data[i+1] = 1; } }else { if(i && data[i-1] == 1 && (i == 1 || data[i-2] <= 1)){ s.erase({data[i-1], i-1}); s.emplace(0, i-1); data[i-1] = 0; } if(i != n-1 && data[i+1] == 1 && (i == n-2 || data[i+2] <= 1)){ s.erase({data[i+1], i+1}); s.emplace(0, i+1); data[i+1] = 0; } } }; ll cnt = 0, time = 0; GPQ Q; for (int i = 0; i < q; ++i) { int a, b; scanf("%d %d", &a, &b); time = max(time, a); if(cnt == n){ // 満席なら追い出す time = max(time, Q.top().first); update(Q.top().second, 0); cnt--; Q.pop(); } while(!Q.empty() && Q.top().first <= time){ time = max(time, Q.top().first); update((int)Q.top().second, 0); cnt--; Q.pop(); } auto x = *s.begin(); printf("%d\n", x.second + 1); Q.emplace(time+b, x.second); update(x.second, 2); cnt++; } return 0; }