結果

問題 No.953 席
ユーザー pekempeypekempey
提出日時 2019-12-16 00:41:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,453 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 184,588 KB
実行使用メモリ 13,892 KB
最終ジャッジ日時 2023-09-15 15:58:26
合計ジャッジ時間 7,777 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 121 ms
7,260 KB
testcase_03 AC 119 ms
6,988 KB
testcase_04 AC 120 ms
7,476 KB
testcase_05 AC 116 ms
6,668 KB
testcase_06 AC 121 ms
7,216 KB
testcase_07 AC 200 ms
13,484 KB
testcase_08 AC 190 ms
12,028 KB
testcase_09 AC 179 ms
13,892 KB
testcase_10 AC 54 ms
6,440 KB
testcase_11 AC 139 ms
9,992 KB
testcase_12 AC 147 ms
10,688 KB
testcase_13 AC 175 ms
11,716 KB
testcase_14 AC 136 ms
9,756 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 127 ms
8,380 KB
testcase_24 WA -
testcase_25 AC 187 ms
11,784 KB
testcase_26 AC 111 ms
6,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

template<class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;

int main() {
  int N, K1, K2;
  cin >> N >> K1 >> K2;
  int Q; cin >> Q;
  set<int> can0, can1;
  const int inf = 1e9;
  can0.insert(-inf);
  can0.insert(inf);
  can1.insert(-inf);
  can1.insert(inf);
  for (int i = 1; i <= N; i++) {
    can0.insert(i);
    can1.insert(i);
  }
  minheap<pair<ll, int>> in, out;
  vector<ll> A(Q), B(Q);
  for (int i = 0; i < Q; i++) {
    cin >> A[i] >> B[i];
    in.emplace(A[i], i);
  }
  vector<int> ans(Q, -1);
  auto ins = [&](int k, int id) {
    ans[id] = k;
    can0.erase(k - 1);
    can0.erase(k);
    can0.erase(k + 1);
    can1.erase(k);
  };
  auto del = [&](int k) {
    can1.insert(k);
    for (int i = max(1, k - 1); i <= min(N, k + 1); i++) {
      if ((i - 1 == 0 || can1.count(i - 1)) && can1.count(i) && (i + 1 == N + 1 || can1.count(i + 1))) {
        can0.insert(i);
      }
    }
  };
  while (!in.empty()) {
    ll now = in.top().first;
    while (!out.empty() && out.top().first <= now) {
      del(ans[out.top().second]);
      out.pop();
    }
    if (can1.size() == 2) {
      now = out.top().first;
    }
    while (!out.empty() && out.top().first <= now) {
      del(ans[out.top().second]);
      out.pop();
    }
    int k = in.top().second;
    in.pop();
    out.emplace(now + B[k], k);
    if (K1 < K2) {
      int l = *prev(can0.upper_bound(K1));
      int r = *can0.lower_bound(K2);
      if (l == -inf && r == inf) {
        int ll = *prev(can1.upper_bound(K1));
        int rr = *can1.lower_bound(K2);
        if (K1 - ll <= rr - K2) {
          ins(ll, k);
        } else {
          ins(rr, k);
        }
      } else if (K1 - l <= r - K2) {
        ins(l, k);
      } else {
        ins(r, k);
      }
    } else {
      int l = *prev(can0.upper_bound(K2));
      int r = *can0.lower_bound(K1);
      if (l == -inf && r == inf) {
        int ll = *prev(can1.upper_bound(K2));
        int rr = *can1.lower_bound(K1);
        if (K2 - ll >= rr - K1) {
          ins(rr, k);
        } else {
          ins(ll, k);
        }
      } else if (K2 - l >= r - K1) {
        ins(r, k);
      } else {
        ins(l, k);
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << ans[i] << '\n';
  }
}
0