結果
問題 | No.953 席 |
ユーザー | 👑 emthrm |
提出日時 | 2019-12-16 00:45:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,803 bytes |
コンパイル時間 | 1,451 ms |
コンパイル使用メモリ | 132,048 KB |
最終ジャッジ日時 | 2025-01-08 11:39:07 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 9 |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #define _USE_MATH_DEFINES #include <cmath> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> 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<int> 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<int> broad, emp; REP(i, n) broad.emplace(i); int q; cin >> q; using P = pair<long long, int>; priority_queue<P, vector<P>, greater<P> > que; while (q--) { long long a, b; cin >> a >> b; while (!que.empty() && (que.top().first <= a || (broad.empty() && emp.empty()))) { int seat = rev[que.top().second]; a = max(a, 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(a + 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; }