Submission #654075

# Submission time Handle Problem Language Result Execution time Memory
654075 2022-10-29T19:03:44 Z thiago_bastos Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"

using namespace std;

void solve(int N) {

	int l = 1, r = N + 1;

	while(l < r) {
		int m = (l + r) / 2;
		if(query(m, N) != N - 1) r = m;
		else l = m + 1;
	}

	int k = r - 1;

	vector<int> P(N + 1, -1);
	vector<bool> vis(N + 1, false);

	P[k] = 1;
	P[k + 1] = 1 + query(k, k + 1);
	
	vis[1] = vis[P[k + 1]] = true;

	auto f = [&](int l, int r, int i) {
		int d = query(min({l,r,i}), max({l,r,i}));

		if(d == abs(P[l] - P[r]))
			P[i] = P[l] > P[r] ? P[l] - query(min(l,i), max(l,i)) : P[l] + query(min(l,i), max(l,i));
		else {
			int lo = min(P[l], P[r]) + d, hi = max(P[l], P[r]) - d;
			if(lo <= N && hi >= 1 && !vis[lo] && !vis[hi]) {
				int d2 = query(min(l,i), max(l,i));
				P[i] = P[l] > P[r] ? (P[l] + (d == d2 ? -d : d2)) : (P[l] + (d == d2 ? d : -d2));
			} else
				P[i] = lo > N || vis[lo] ? hi : lo;
		}
		vis[P[i]] = true;
	};

	for(int i = k + 2; i <= N; ++i) f(i - 1, i - 2, i);
	for(int i = k - 1; i; --i) f(i + 1, i + 2, i);
	for(int i = 1; i <= N; ++i) answer(i, P[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:11:6: error: 'query' was not declared in this scope
   11 |   if(query(m, N) != N - 1) r = m;
      |      ^~~~~
xylophone.cpp:21:17: error: 'query' was not declared in this scope
   21 |  P[k + 1] = 1 + query(k, k + 1);
      |                 ^~~~~
xylophone.cpp:43:30: error: 'answer' was not declared in this scope
   43 |  for(int i = 1; i <= N; ++i) answer(i, P[i]);
      |                              ^~~~~~