結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-04 14:25:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,711 bytes |
| コンパイル時間 | 1,533 ms |
| コンパイル使用メモリ | 110,596 KB |
| 最終ジャッジ日時 | 2025-01-12 14:15:23 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 22 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
void solve() {
int n, k1, k2;
std::cin >> n >> k1 >> k2;
bool first1 = true;
if (k1 > k2) {
first1 = false;
std::swap(k1, k2);
}
// k1 < k2
std::set<int> s1{0, n + 1};
for (int i = 1; i <= n; ++i) s1.insert(i);
auto s2 = s1;
int m;
std::cin >> m;
std::map<int, std::vector<int>> ts;
for (int i = 1; i <= m; ++i) {
int a, b;
std::cin >> a >> b;
ts[a].push_back(i);
ts[a + b].push_back(-i);
}
auto max = [&](int l, int r) -> int {
int dl = k1 - l, dr = r - k2;
if (dl != dr) {
return dl < dr ? l : r;
} else {
return first1 ? l : r;
}
};
auto get = [&]() -> int {
int l = *(--s1.lower_bound(k2));
int r = *s1.lower_bound(k2);
int i = max(l, r);
if (i == 0 || i == n + 1) {
l = *(--s2.lower_bound(k2));
r = *s2.lower_bound(k2);
i = max(l, r);
if (i == 0 || i == n + 1) return -1;
}
s2.erase(i);
for (int d = -1; d <= 1; ++d) {
if (1 <= i + d && i + d <= n) s1.erase(i + d);
}
return i;
};
auto dump = [&]() {
std::cerr << "\ns1: ";
for (auto i : s1)
if (1 <= i && i <= n) std::cerr << i << " ";
std::cerr << "\n";
std::cerr << "s2: ";
for (auto i : s2)
if (1 <= i && i <= n) std::cerr << i << " ";
std::cerr << "\n";
};
std::vector<int> ans(m);
std::queue<int> que;
for (auto& [t, v] : ts) {
std::sort(v.begin(), v.end());
for (auto x : v) {
if (x < 0) {
// dump();
int i = ans[-x - 1];
s2.insert(i);
if (i - 1 >= 0 && s2.count(i - 1) && s2.count(i - 2)) {
s1.insert(i - 1);
}
if (s2.count(i - 1) && s2.count(i + 1)) {
s1.insert(i);
}
if (i + 1 < n && s2.count(i + 1) && s2.count(i + 2)) {
s1.insert(i + 1);
}
} else {
que.push(x);
}
}
while (!que.empty()) {
// dump();
int i = get();
if (i == -1) break;
int x = que.front();
que.pop();
ans[x - 1] = i;
}
}
for (auto a : ans) std::cout << a << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}