結果
問題 | No.953 席 |
ユーザー | FF256grhy |
提出日時 | 2019-12-16 03:28:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 334 ms / 2,000 ms |
コード長 | 3,569 bytes |
コンパイル時間 | 1,832 ms |
コンパイル使用メモリ | 183,800 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-07-02 19:07:24 |
合計ジャッジ時間 | 10,393 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 253 ms
5,376 KB |
testcase_03 | AC | 265 ms
5,376 KB |
testcase_04 | AC | 250 ms
5,376 KB |
testcase_05 | AC | 250 ms
5,376 KB |
testcase_06 | AC | 254 ms
5,376 KB |
testcase_07 | AC | 279 ms
8,448 KB |
testcase_08 | AC | 317 ms
7,288 KB |
testcase_09 | AC | 237 ms
9,216 KB |
testcase_10 | AC | 84 ms
5,376 KB |
testcase_11 | AC | 240 ms
6,144 KB |
testcase_12 | AC | 284 ms
5,632 KB |
testcase_13 | AC | 310 ms
7,048 KB |
testcase_14 | AC | 272 ms
5,376 KB |
testcase_15 | AC | 267 ms
5,376 KB |
testcase_16 | AC | 271 ms
5,376 KB |
testcase_17 | AC | 289 ms
5,504 KB |
testcase_18 | AC | 280 ms
5,376 KB |
testcase_19 | AC | 334 ms
6,872 KB |
testcase_20 | AC | 280 ms
5,376 KB |
testcase_21 | AC | 257 ms
5,376 KB |
testcase_22 | AC | 284 ms
6,396 KB |
testcase_23 | AC | 258 ms
5,376 KB |
testcase_24 | AC | 262 ms
5,376 KB |
testcase_25 | AC | 324 ms
7,292 KB |
testcase_26 | AC | 236 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using LL = long long int; #define incID(i, l, r) for(int i = (l) ; i < (r); ++i) #define incII(i, l, r) for(int i = (l) ; i <= (r); ++i) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i) #define decII(i, l, r) for(int i = (r) ; i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() auto setmin = [](auto & a, auto b) { return (b < a ? a = b, true : false); }; auto setmax = [](auto & a, auto b) { return (b > a ? a = b, true : false); }; auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); }; auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); }; auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); }; auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); }; auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; }; LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); } LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define SI(v) static_cast<int>(v.size()) #define RF(e, v) for(auto & e: v) #define until(e) while(! (e)) #define if_not(e) if(! (e)) #define ef else if #define UR assert(false) // ---- ---- #define GPQ priority_queue template<typename T> class LPQ : public GPQ<T, vector<T>, greater<T>> { }; int main() { int n; cin >> n; vector<int> pos(n), ord(n, -1); cin >> pos[0] >> pos[1]; pos[0]--; pos[1]--; ord[pos[0]] = 0; ord[pos[1]] = 1; incID(i, 2, n) { int x = pos[i - 1]; int y = pos[i - 2]; if(x < y) { x--; y++; } else { y--; x++; } pos[i] = (inID(y, 0, n) && ord[y] == -1 ? y : x); ord[pos[i]] = i; } vector<int> state(n, 0); set<pair<int, int>> SEAT; inc(i, n) { SEAT.emplace(0, i); } LPQ<pair<LL, int>> out; auto check = [&](int pos) { if_not(inID(pos, 0, n)) { return; } SEAT.erase({ 0, ord[pos] }); SEAT.erase({ 1, ord[pos] }); if(state[pos] == 2) { return; } bool x = (pos == 0 || state[pos - 1] <= 1); bool y = (pos == n - 1 || state[pos + 1] <= 1); state[pos] = (x && y ? 0 : 1); SEAT.emplace(state[pos], ord[pos]); }; auto IN = [&](int pos) { // cout << "IN: " << pos + 1 << endl; assert(state[pos] <= 1); state[pos] = 2; check(pos ); check(pos - 1); check(pos + 1); }; auto OUT = [&](int pos) { // cout << "OUT: " << pos + 1 << endl; assert(state[pos] == 2); state[pos] = 0; check(pos ); check(pos - 1); check(pos + 1); }; auto print = [&]() { inc(i, n) { cout << "OoX"[state[i]]; } cout << endl; }; LL time = 0; int q; cin >> q; inc(i, q) { LL a, b; cin >> a >> b; setmax(time, a); // time = a; // test { while(SI(out) > 0 && out.top().FI <= time) { OUT(out.top().SE); out.pop(); } } if(SI(SEAT) == 0) { time = out.top().FI; while(SI(out) > 0 && out.top().FI == time) { OUT(out.top().SE); out.pop(); } } // cout << "t = " << time << endl; // print(); int p = pos[SEAT.begin() -> SE]; IN(p); out.emplace(time + b, p); // print(); cout << p + 1 << "\n"; // cout << endl; } return 0; }