結果

問題 No.953 席
ユーザー FF256grhyFF256grhy
提出日時 2019-12-16 01:58:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 3,348 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 182,532 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2023-09-15 16:23:18
合計ジャッジ時間 7,252 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 113 ms
5,208 KB
testcase_03 AC 111 ms
5,120 KB
testcase_04 AC 112 ms
5,340 KB
testcase_05 AC 108 ms
4,696 KB
testcase_06 AC 113 ms
5,216 KB
testcase_07 AC 183 ms
9,300 KB
testcase_08 AC 179 ms
8,496 KB
testcase_09 AC 163 ms
9,644 KB
testcase_10 AC 56 ms
5,252 KB
testcase_11 AC 134 ms
6,956 KB
testcase_12 AC 137 ms
7,060 KB
testcase_13 AC 162 ms
8,296 KB
testcase_14 AC 127 ms
6,912 KB
testcase_15 AC 124 ms
6,532 KB
testcase_16 AC 126 ms
6,660 KB
testcase_17 AC 148 ms
7,160 KB
testcase_18 AC 140 ms
6,928 KB
testcase_19 AC 177 ms
8,240 KB
testcase_20 AC 137 ms
6,676 KB
testcase_21 AC 118 ms
5,348 KB
testcase_22 AC 139 ms
7,540 KB
testcase_23 AC 117 ms
5,800 KB
testcase_24 AC 118 ms
5,848 KB
testcase_25 AC 178 ms
8,480 KB
testcase_26 AC 100 ms
4,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++; }
		if(y < x) { y--; x++; }
		pos[i] = (inID(y, 0, n) && ord[y] == -1 ? y : x);
		ord[pos[i]] = i;
	}
	
	int q;
	cin >> q;
	vector<LL> a(q), b(q);
	inc(i, q) { cin >> a[i] >> b[i]; }
	
	LPQ<pair<LL, int>> out;
	set<pair<int, int>> SEAT;
	vector<int> state(n, 0);
	inc(i, n) { SEAT.emplace(state[i], i); }
	
	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) {
		assert(state[pos] <= 1);
		state[pos] = 2;
		check(pos    );
		check(pos - 1);
		check(pos + 1);
	};
	auto OUT = [&](int pos) {
		assert(state[pos] == 2);
		state[pos] = 0;
		check(pos    );
		check(pos - 1);
		check(pos + 1);
	};
	
	LL time = 0;
	inc(i, q) {
		setmax(time, a[i]);
		{
			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(); }
		}
		
		auto p = * SEAT.begin();
		IN(pos[p.SE]);
		out.emplace(time + b[i], pos[p.SE]);
		cout << pos[p.SE] + 1 << "\n";
	}
	
	return 0;
}
0