結果
| 問題 |
No.953 席
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-23 22:01:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,573 bytes |
| コンパイル時間 | 2,595 ms |
| コンパイル使用メモリ | 222,064 KB |
| 最終ジャッジ日時 | 2025-01-12 04:35:55 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 18 TLE * 5 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> order;
struct Comp {
bool operator() (const pair<int, int>& x, const pair<int, int>& y) const {
if (x.first != y.first) return x.first < y.first;
return order[x.second] < order[y.second];
}
};
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int n, k1, k2;
cin >> n >> k1 >> k2;
order = vector<int>(n + 1);
order[k1] = 0;
order[k2] = 1;
int c = 2;
for (int i = k1 - 1; i >= 1; i--) {
order[i] = c;
c += 2;
}
c = 3;
for (int i = k2 + 1; i <= n; i++) {
order[i] = c;
c += 2;
}
set<pair<int, int>, Comp> available;
vector<bool> occupy(n + 5);
auto whenCome = [&] (int idx) {
occupy[idx] = true;
available.erase(make_pair(0, idx));
available.erase(make_pair(1, idx));
if (idx - 1 >= 1 && !occupy[idx - 1]) {
available.erase(make_pair(0, idx - 1));
available.insert(make_pair(1, idx - 1));
}
if (idx + 1 <= n && !occupy[idx + 1]) {
available.erase(make_pair(0, idx + 1));
available.insert(make_pair(1, idx + 1));
}
};
auto whenLeave = [&] (int idx) {
occupy[idx] = false;
if (!occupy[idx - 1] && !occupy[idx + 1]) available.insert(make_pair(0, idx));
else available.insert(make_pair(1, idx));
};
for (int i = 1; i <= n; i++) available.insert(make_pair(0, i));
int q;
cin >> q;
vector<int> ans(q);
map<int, vector<int>> come;
map<int, vector<int>> leave;
vector<int> time;
for (int i = 0; i < q; i++) {
int a, b;
cin >> a >> b;
come[a].push_back(i);
leave[a + b].push_back(i);
time.push_back(a);
time.push_back(a + b);
}
sort(time.begin(), time.end());
queue<int> postpone;
for (auto t : time) {
if (leave.count(t)) {
for (auto p : leave[t]) {
int idx = ans[p];
whenLeave(idx);
}
}
while (!available.empty() && !postpone.empty()) {
int p = postpone.front();
postpone.pop();
int idx = available.begin()->second;
ans[p] = idx;
whenCome(idx);
}
if (come.count(t)) {
for (auto p : come[t]) {
if (available.empty()) postpone.push(p);
else {
int idx = available.begin()->second;
ans[p] = idx;
whenCome(idx);
}
}
}
}
while (!available.empty() && !postpone.empty()) {
int p = postpone.front();
postpone.pop();
int idx = available.begin()->second;
ans[p] = idx;
whenCome(idx);
}
for (auto& x : ans) cout << x << '\n';
return 0;
}