結果

問題 No.953 席
ユーザー FF256grhyFF256grhy
提出日時 2019-12-16 02:49:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,569 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 182,992 KB
実行使用メモリ 8,840 KB
最終ジャッジ日時 2023-09-15 16:38:51
合計ジャッジ時間 10,504 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 249 ms
4,376 KB
testcase_03 AC 253 ms
4,380 KB
testcase_04 AC 250 ms
4,376 KB
testcase_05 AC 244 ms
4,380 KB
testcase_06 AC 252 ms
4,376 KB
testcase_07 AC 276 ms
8,248 KB
testcase_08 AC 320 ms
7,016 KB
testcase_09 AC 237 ms
8,840 KB
testcase_10 AC 85 ms
4,964 KB
testcase_11 AC 240 ms
5,960 KB
testcase_12 AC 280 ms
5,544 KB
testcase_13 AC 313 ms
6,668 KB
testcase_14 AC 268 ms
5,044 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 258 ms
4,596 KB
testcase_24 WA -
testcase_25 AC 328 ms
6,900 KB
testcase_26 AC 233 ms
4,380 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++; } 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;
}
0