結果

問題 No.953 席
ユーザー MayimgMayimg
提出日時 2020-07-24 01:16:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,320 bytes
コンパイル時間 2,725 ms
コンパイル使用メモリ 224,608 KB
実行使用メモリ 9,724 KB
最終ジャッジ日時 2023-09-06 06:06:16
合計ジャッジ時間 6,767 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 58 ms
6,300 KB
testcase_03 AC 55 ms
5,940 KB
testcase_04 AC 58 ms
6,328 KB
testcase_05 AC 51 ms
5,964 KB
testcase_06 AC 55 ms
6,168 KB
testcase_07 AC 113 ms
9,512 KB
testcase_08 WA -
testcase_09 AC 102 ms
9,724 KB
testcase_10 AC 29 ms
5,344 KB
testcase_11 AC 77 ms
7,524 KB
testcase_12 AC 76 ms
8,056 KB
testcase_13 AC 94 ms
9,420 KB
testcase_14 AC 71 ms
7,656 KB
testcase_15 AC 68 ms
7,600 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 64 ms
6,808 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 37 ms
5,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  if (k2 > k1) {
    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;
    }
  } else {
    int c = 2;
    for (int i = k1 + 1; i <= n; i++) {
      order[i] = c;
      c += 2;
    }
    c = 3;
    for (int i = k2 - 1; i >= 1; 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));
    if (!occupy[idx - 1]) {
      if (idx - 1 >= 1 && !occupy[idx - 2]) {
        available.erase(make_pair(1, idx - 1));
        available.insert(make_pair(0, idx - 1));
      }
    }
    if (!occupy[idx + 1]) {
      if (idx + 1 <= n && !occupy[idx + 2]) {
        available.erase(make_pair(1, idx + 1));
        available.insert(make_pair(0, idx + 1));
      }
    }
  };
  auto come = [&] () {
    if (available.empty()) return -1;
    int idx = available.begin()->second;
    whenCome(idx);
    return idx;
  };
  for (int i = 1; i <= n; i++) available.insert(make_pair(0, i));
  int q;
  cin >> q;
  vector<long long> a(q), b(q);
  for (int i = 0; i < q; i++) cin >> a[i] >> b[i];
  auto aa = a;
  {
    priority_queue<long long, vector<long long>, greater<long long>> que;
    for (int i = 0; i < q; i++) {
      if (i == 86515 || i == 86515 - 1) {
        //cerr << i << " " << a[i] << " " << que.size() << " " << (que.empty() ? -1LL : que.top()) << endl;
        while (!que.empty() && que.top() <= a[i]) que.pop();
        //cerr << i << " " << a[i] << " " << que.size() << " " << (que.empty() ? -1LL : que.top()) << endl;
        if ((int) que.size() < n) {
          if (!que.empty() && que.top() > a[i]) {
            a[i] = a[i - 1];
          }
          que.push(a[i] + b[i]);
          continue;
        }
        long long mx = que.top();
        while (!que.empty() && que.top() <= mx) que.pop();
        a[i] = mx;
        //cerr << a[i] << " " << a[i] + b[i] << endl;
        que.push(a[i] + b[i]);
      } else {
        while (!que.empty() && que.top() <= a[i]) que.pop();
        //cout << i << " " << que.size() << " " << (que.empty() ? -1LL : que.top()) << endl;
        if ((int) que.size() < n) {
          que.push(a[i] + b[i]);
          continue;
        }
        long long mx = que.top();
        while (!que.empty() && que.top() <= mx) que.pop();
        a[i] = mx;
        que.push(a[i] + b[i]);
      }
    }
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> que;
  vector<int> ans(q);
  for (int i = 0; i < q; i++) {
    while (!que.empty() && que.top().first <= a[i]) {
      int p = que.top().second;
      que.pop();
      whenLeave(ans[p]);
    }
    int idx = come();
    ans[i] = idx;
    que.emplace(a[i] + b[i], i);
  }
  for (int i = 1; i < q; i++) {
    // if (a[i - 1] > a[i]) cerr << i << endl;
    // assert(a[i - 1] <= a[i]);
  }
  // vector<int> c_ans(q);
  // for (int i = 0; i < q; i++) cin >> c_ans[i];
  // for (int i = 0; i < q; i++) {
  //   cout << ans[i] << " " << c_ans[i] << " " << " " << aa[i] << " " << a[i] << " " << a[i] + b[i] << " correct =  " << (ans[i] == c_ans[i]) << '\n';
  // }
  // return 0;
  for (auto& x : ans) cout << x << '\n';
  return 0;
}
0