Submission #838873

# Submission time Handle Problem Language Result Execution time Memory
838873 2023-08-28T03:24:01 Z pavement Minerals (JOI19_minerals) C++17
0 / 100
2 ms 464 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair

void Solve(int N) {
	vector<int> uniq, others;
	for (int i = 0, prv = 0; i < 2 * N; i++) {
		if (Query(i + 1) > prv) {
			uniq.pb(i);
			prv++;
		} else {
			others.pb(i);
		}
	}
	for (int i = 0; i < 2 * N; i++) {
		Query(i + 1);
	}
	vector<int> lo(2 * N, 0), hi(2 * N, N - 1), mid(2 * N), ans(2 * N, -1);
	int cur_l = -1, cur_r = -1, prv = -1;
	
	auto shift = [&](int new_l, int new_r) {
		if (cur_l == -1 || cur_r - cur_l + 1 + new_r - new_l + 1 < abs(cur_l - new_l) + abs(cur_r - new_r)) {
			if (cur_l != -1) {
				for (int i = cur_l; i <= cur_r; i++) {
					prv = Query(uniq[i] + 1);
				}
			}
			for (int i = new_l; i <= new_r; i++) {
				prv = Query(uniq[i] + 1);
			}
		} else {
			if (new_l <= cur_l) {
				for (int i = cur_l - 1; i >= new_l; i--) {
					prv = Query(uniq[i] + 1);
				}
				if (new_r <= cur_r) {
					for (int i = cur_r; i > new_r; i--) {
						prv = Query(uniq[i] + 1);
					}
				} else {
					for (int i = cur_r + 1; i <= new_r; i++) {
						prv = Query(uniq[i] + 1);
					}
				}
			} else {
				if (new_r <= cur_r) {
					for (int i = cur_r; i > new_r; i--) {
						prv = Query(uniq[i] + 1);
					}
				} else {
					for (int i = cur_r + 1; i <= new_r; i++) {
						prv = Query(uniq[i] + 1);
					}
				}
				for (int i = cur_l; i < new_l; i++) {
					prv = Query(uniq[i] + 1);
				}
			}
		}
		cur_l = new_l;
		cur_r = new_r;
	};
	
	for (int rep = 0; (1 << rep) <= N; rep++) {
		vector<bool> can(2 * N, 0);
		for (int i : others) {
			mid[i] = (lo[i] + hi[i]) / 2;
			// insert [lo[i], mid[i]] from uniq
		}
		sort(others.begin(), others.end(), [&](const auto &lhs, const auto &rhs) {
			return (mp(lo[lhs], mid[rhs]) < mp(lo[rhs], mid[rhs])) ^ (rep % 2);
		});
		for (int i : others) {
			shift(lo[i], mid[i]);
			int ret_1 = Query(i + 1);
			if (ret_1 == prv) {
				can[i] = 1;
			}
			prv = ret_1;
		}
		for (int i : others) {
			if (can[i]) {
				ans[i] = mid[i];
				hi[i] = mid[i] - 1;
			} else {
				lo[i] = mid[i] + 1;
			}
		}
	}
	for (int i : others) {
		Answer(i + 1, uniq[ans[i]] + 1);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -