#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; // const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, // dx[] = {0, -1, -1, -1, 0, 1, 1, 1}; struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(10); } } iosetup; /*-------------------------------------------------*/ int main() { int n, k1, k2; cin >> n >> k1 >> k2; --k1; --k2; vector idx(n), rev(n); int now = 0; idx[k1] = now; rev[now] = k1; ++now; for (int dist = 1; dist < n; ++dist) { if (k1 < k2) { if (k1 + dist < n) { idx[k1 + dist] = now; rev[now] = k1 + dist; ++now; } if (k1 - dist >= 0) { idx[k1 - dist] = now; rev[now] = k1 - dist; ++now; } } else { if (k1 - dist >= 0) { idx[k1 - dist] = now; rev[now] = k1 - dist; ++now; } if (k1 + dist < n) { idx[k1 + dist] = now; rev[now] = k1 + dist; ++now; } } } // REP(i, n) cout << rev[i] << ' '; // cout << '\n'; set broad, emp; REP(i, n) broad.emplace(i); int q; cin >> q; using P = pair; priority_queue, greater

> que; long long cur = 0; while (q--) { long long a, b; cin >> a >> b; cur = max(cur, a); while (!que.empty() && (que.top().first <= cur || (broad.empty() && emp.empty()))) { int seat = rev[que.top().second]; cur = max(cur, que.top().first); que.pop(); bool br = true; if (seat - 1 >= 0) { int seat_l = seat - 1; if (emp.count(idx[seat_l]) == 1) { if (seat_l - 1 < 0 || (broad.count(idx[seat_l - 1]) == 1 || emp.count(idx[seat_l - 1]) == 1)) { emp.erase(idx[seat_l]); broad.emplace(idx[seat_l]); } } else { br = false; } } if (seat + 1 < n) { int seat_r = seat + 1; if (emp.count(idx[seat_r]) == 1) { if (seat_r + 1 >= n || (broad.count(idx[seat_r + 1]) == 1 || emp.count(idx[seat_r + 1]) == 1)) { emp.erase(idx[seat_r]); broad.emplace(idx[seat_r]); } } else { br = false; } } (br ? broad : emp).emplace(idx[seat]); } int seat; if (!broad.empty()) { seat = *broad.begin(); broad.erase(seat); } else { seat = *emp.begin(); emp.erase(seat); } cout << rev[seat] + 1 << '\n'; que.emplace(cur + b, seat); if (rev[seat] - 1 >= 0) { int seat_l = idx[rev[seat] - 1]; if (broad.count(seat_l) == 1) { broad.erase(seat_l); emp.emplace(seat_l); } } if (rev[seat] + 1 < n) { int seat_r = idx[rev[seat] + 1]; if (broad.count(seat_r) == 1) { broad.erase(seat_r); emp.emplace(seat_r); } } // cout << "broad: "; // for (int e : broad) cout << e << ' '; // cout << '\n'; // cout << "emp: "; // for (int e : emp) cout << e << ' '; // cout << '\n'; } return 0; }