#include // created [2019/12/15] 17:30:14 #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; using uint = unsigned int; using usize = std::size_t; using ll = long long; using ull = unsigned long long; using ld = long double; template using arr = T (&)[n]; template using c_arr = const T (&)[n]; template constexpr T popcount(const T u) { return u ? static_cast(__builtin_popcountll(static_cast(u))) : static_cast(0); } template constexpr T log2p1(const T u) { return u ? static_cast(64 - __builtin_clzll(static_cast(u))) : static_cast(0); } template constexpr T msbp1(const T u) { return log2p1(u); } template constexpr T lsbp1(const T u) { return __builtin_ffsll(u); } template constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast(u); } template constexpr bool ispow2(const T u) { return u and (static_cast(u) & static_cast(u - 1)) == 0; } template constexpr T ceil2(const T u) { return static_cast(1) << clog(u); } template constexpr T floor2(const T u) { return u == 0 ? static_cast(0) : static_cast(1) << (log2p1(u) - 1); } template constexpr bool btest(const T mask, const usize ind) { return static_cast((static_cast(mask) >> ind) & static_cast(1)); } template void bset(T& mask, const usize ind) { mask |= (static_cast(1) << ind); } template void breset(T& mask, const usize ind) { mask &= ~(static_cast(1) << ind); } template void bflip(T& mask, const usize ind) { mask ^= (static_cast(1) << ind); } template void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast(0) : static_cast((static_cast(mask) << (64 - ind)) >> (64 - ind)); } template bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } constexpr unsigned int mod = 1000000007; template constexpr T inf_v = std::numeric_limits::max() / 4; template constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; auto fix_point = [](auto f) { return [=](auto&&... args) { return f(f, std::forward(args)...); }; }; template T in() { T v; return std::cin >> v, v; } template T in_v(typename std::enable_if<(i == n), c_arr>::type) { return in(); } template auto in_v(typename std::enable_if<(i < n), c_arr>::type& szs) { const usize s = (usize)szs[i]; std::vector(szs))> ans(s); for (usize j = 0; j < s; j++) { ans[j] = in_v(szs); } return ans; } template auto in_v(c_arr szs) { return in_v(szs); } template auto in_t() { return std::tuple...>{in()...}; } struct io_init { io_init() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(20); } } hogechan; template void out(const T& v) { std::cout << v; } template void out(const std::vector& v) { for (usize i = 0; i < v.size(); i++) { if (i > 0) { std::cout << ' '; } out(v[i]); } std::cout << "\n"; } template void out(const std::pair& v) { out(v.first), std::cout << ' ', out(v.second); } template void out(const T& v, const Args... args) { out(v), std::cout << ' ', out(args...); } template void outln(const Args... args) { out(args...), std::cout << '\n'; } template void outel(const Args... args) { out(args...), std::cout << std::endl; } # define SHOW(...) static_cast(0) constexpr ull TEN(const usize n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; } template auto make_v(typename std::enable_if<(i == n), c_arr>::type, const T& v = T{}) { return v; } template auto make_v(typename std::enable_if<(i < n), c_arr>::type szs, const T& v = T{}) { const usize s = (usize)szs[i]; return std::vector(szs, v))>(s, make_v(szs, v)); } template auto make_v(c_arr szs, const T& t = T{}) { return make_v(szs, t); } int main() { const auto N = in(); const auto K1 = in(); const auto K2 = in(); const auto D = K1 * 2 + K2; auto comp = [D](const int k1, const int k2) { return std::abs(3 * k1 - D) < std::abs(3 * k2 - D); }; std::vector empty(N + 2, true); std::set seats(comp); std::set good_seats(comp); for (int i = 1; i <= N; i++) { seats.insert(i); good_seats.insert(i); } auto good = [&](const int k) { if (k < 1 or k > N) { return false; } return empty[k - 1] and empty[k] and empty[k + 1]; }; auto sit_at = [&](const int k) { assert(empty[k]); empty[k] = false; seats.erase(k); if (not good(k)) { good_seats.erase(k); } if (not good(k - 1)) { good_seats.erase(k - 1); } if (not good(k + 1)) { good_seats.erase(k + 1); } }; auto sit = [&]() -> int { using pbi = std::pair; pbi ans{false, inf_v}; for (int i = 1; i <= N; i++) { if (not empty[i]) { continue; } const pbi res{good(i), i}; ans = std::min(ans, res, [&](const pbi& p1, const pbi& p2) { return p1.first != p2.first ? p1.first > p2.first : comp(p1.second, p2.second); }); } const int k = ans.second; if (k == inf_v) { return 0; } empty[k] = false; return k; }; auto leave = [&](const int k) { empty[k] = true; }; // auto sit = [&]() -> int { // if (not good_seats.empty()) { // const int k = *good_seats.begin(); // sit_at(k); // return k; // } else if (not seats.empty()) { // const int k = *seats.begin(); // sit_at(k); // return k; // } else { // return 0; // } // }; // auto leave = [&](const int k) { // assert(not empty[k]); // empty[k] = true; // seats.insert(k); // if (good(k)) { good_seats.insert(k); } // if (good(k - 1)) { good_seats.insert(k - 1); } // if (good(k + 1)) { good_seats.insert(k + 1); } // }; using pli = std::pair; const auto Q = in(); std::vector a(Q), b(Q); for (int i = 0; i < Q; i++) { a[i] = in(), b[i] = in(); } std::set ls; ll tim = 0; for (int i = 0; i < Q; i++) { chmax(tim, a[i]); while (not ls.empty() and ls.begin()->first <= tim) { const auto info = *ls.begin(); ls.erase(ls.begin()); leave(info.second); } int k = 0; while ((k = sit()) == 0) { const auto info = *ls.begin(); tim = info.first; while (not ls.empty() and ls.begin()->first == tim) { leave(ls.begin()->second); ls.erase(ls.begin()); } } ls.insert({tim + b[i], k}); outln(k); } return 0; }