結果

問題 No.953 席
ユーザー square1001square1001
提出日時 2020-02-03 23:39:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,408 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 106,228 KB
実行使用メモリ 10,288 KB
最終ジャッジ日時 2023-10-19 15:19:24
合計ジャッジ時間 10,034 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 254 ms
10,004 KB
testcase_08 AC 287 ms
8,836 KB
testcase_09 AC 212 ms
10,288 KB
testcase_10 AC 67 ms
5,504 KB
testcase_11 AC 199 ms
7,720 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 237 ms
9,088 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 273 ms
8,860 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
class query {
public:
	int tp, id; long long t;
	query() : tp(-1), t(-1), id(-1) {};
	query(int tp_, int t_, int id_) : tp(tp_), t(t_), id(id_) {};
	bool operator<(const query& q) const {
		return t * 2 - tp > q.t * 2 - q.tp;
	}
};
int main() {
	int N, K1, K2;
	cin >> N >> K1 >> K2; --K1, --K2;
	vector<int> ord(N);
	for (int i = 0; i < N; ++i) {
		int d1 = abs(i - K1), d2 = abs(i - K2);
		if (d1 < d2) {
			ord[i] = 2 * d1;
		}
		else {
			ord[i] = 2 * d2 + 1;
		}
	}
	vector<int> ordsorted = ord;
	sort(ordsorted.begin(), ordsorted.end());
	for (int i = 0; i < N; ++i) {
		ord[i] = lower_bound(ordsorted.begin(), ordsorted.end(), ord[i]) - ordsorted.begin();
	}
	vector<int> ordinv(N);
	for (int i = 0; i < N; ++i) {
		ordinv[ord[i]] = i;
	}
	int Q;
	cin >> Q;
	vector<int> A(Q), B(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> A[i] >> B[i];
	}
	priority_queue<query> que;
	for (int i = 0; i < Q; ++i) {
		que.push(query(0, A[i], i));
	}
	queue<int> que2;
	set<int> sl;
	vector<int> state(N, 0);
	for (int i = 0; i < N; ++i) {
		sl.insert(i);
	}
	vector<int> ans(Q);
	while (!que.empty()) {
		query u = que.top(); que.pop();
		bool repeat = (!que.empty() && u.t == que.top().t);
		if (u.tp == 0) {
			int val = *sl.begin();
			if (val >= 2 * N) {
				que2.push(u.id);
			}
			else {
				val = ordinv[val % N];
				sl.erase(state[val] * N + ord[val]);
				state[val] = 2;
				sl.insert(state[val] * N + ord[val]);
				for (int i = val - 1; i <= val + 1; i += 2) {
					if (!(0 <= i && i < N) || state[i] == 2) continue;
					bool flag = false;
					if (i >= 1 && state[i - 1] == 2) flag = true;
					if (i <= N - 2 && state[i + 1] == 2) flag = true;
					sl.erase(state[i] * N + ord[i]);
					state[i] = (flag ? 1 : 0);
					sl.insert(state[i] * N + ord[i]);
				}
				ans[u.id] = val;
				que.push(query(1, u.t + B[u.id], val));
			}
		}
		if (u.tp == 1) {
			int val = u.id;
			sl.erase(state[val] * N + ord[val]);
			bool pflag = false;
			if (val >= 1 && state[val - 1] == 2) pflag = true;
			if (val <= N - 2 && state[val + 1] == 2) pflag = true;
			state[val] = (pflag ? 1 : 0);
			sl.insert(state[val] * N + ord[val]);
			for (int i = val - 1; i <= val + 1; i += 2) {
				if (!(0 <= i && i < N) || state[i] == 2) continue;
				bool flag = false;
				if (i >= 1 && state[i - 1] == 2) flag = true;
				if (i <= N - 2 && state[i + 1] == 2) flag = true;
				sl.erase(state[i] * N + ord[i]);
				state[i] = (flag ? 1 : 0);
				sl.insert(state[i] * N + ord[i]);
			}
		}
		while (!repeat && !que2.empty()) {
			int id = que2.front();
			int val = *sl.begin();
			if (val >= 2 * N) {
				break;
			}
			else {
				que2.pop();
				val = ordinv[val % N];
				sl.erase(state[val] * N + ord[val]);
				state[val] = 2;
				sl.insert(state[val] * N + ord[val]);
				for (int i = val - 1; i <= val + 1; i += 2) {
					if (!(0 <= i && i < N) || state[i] == 2) continue;
					bool flag = false;
					if (i >= 1 && state[i - 1] == 2) flag = true;
					if (i <= N - 2 && state[i + 1] == 2) flag = true;
					sl.erase(state[i] * N + ord[i]);
					state[i] = (flag ? 1 : 0);
					sl.insert(state[i] * N + ord[i]);
				}
				que.push(query(1, u.t + B[id], val));
				ans[id] = val;
			}
		}
	}
	for (int i = 0; i < Q; ++i) {
		cout << ans[i] + 1 << '\n';
	}
	return 0;
}
0