Submission #1324289

#TimeUsernameProblemLanguageResultExecution timeMemory
1324289adscodingXylophone (JOI18_xylophone)C++20
Compilation error
0 ms0 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void __prine_one(const char *&s, const T &x)
{
	while (*s == ' ') ++s;
	const char *p = s;
	int bal = 0;
	while (*s)
	{
		if (*s == '(') ++bal;
		else if (*s == ')') --bal;
		else if (*s == ',' && bal == 0) break;
		++s;
	}
	cerr.write(p, s - p) << " = " << x;
	if (*s == ',')
	{
		cerr << "  ,  ";
		++s;
	}
}

template<typename... Args>
void debug(const char *s, Args... args)
{
	cerr << "[  ";
	int dummy[] = {0, (__prine_one(s, args), 0)...};
	(void)dummy;
	cerr << "  ]\n\n";
}

template<class X>
bool maximize(X &a, const X &b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template<class X>
bool minimize(X &a, const X &b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}

// --------------------------------------------------------------------------------------------

const int maxn = 1e5 + 3;
int n, a[maxn], RES[maxn];
bool mark[maxn];

// --------------------------------------------------------------------------------------------


int query(int l, int r)
{
	cout << "? " << l << ' ' << r << endl;
	int x; cin >> x;
	return x;
}

void answer(int i, int x)
{
	cout << i << ' ' << x << endl;
}

bool valid(int x)
{
	return x >= 1 && x <= n && !mark[x];
}

int get_ans(int root, int so, int delta)
{
	if (root < so)
		return root + delta;
	return root - delta;
}

void solve(int n)
{
	int l = 1, r = n;
	while (l <= r)
	{
		int mid = l + r >> 1;
		if (query(mid, n) == n - 1)
			l = mid + 1;
		else
			r = mid - 1;
	}
	int pos1 = r;
	a[pos1] = 1;
	mark[1] = true;
	pii cur = {0, 0};
	if (pos1 < n)
	{
		RES[pos1] = query(pos1, pos1 + 1);
		a[pos1 + 1] = RES[pos1] + 1;
		FOR(i, pos1 + 2, n)
		{
			mark[a[i - 1]] = true;
			RES[i - 1] = query(i - 1, i);
			if (!valid(a[i - 1] + RES[i - 1]))
			{
				a[i] = a[i - 1] - RES[i - 1];
				continue;
			}
			else if (!valid(a[i - 1] - RES[i - 1]))
			{
				a[i] = a[i - 1] + RES[i - 1];
				continue;
			}

			int cur = query(i - 2, i);
			if (cur == RES[i - 1])
				a[i] = get_ans(a[i - 1], a[i - 2], cur);
			else if (cur == RES[i - 2])
				a[i] = get_ans(a[i - 1], a[i - 2], RES[i - 1]);
			else
				a[i] = get_ans(a[i - 2], a[i - 1], cur);
		}
	}
	if (pos1 > 1)
	{
		RES[pos1 - 1] = query(pos1 - 1, pos1);
		a[pos1 - 1] = RES[pos1 - 1] + 1;
		FORD(i, pos1 - 2, 1)
		{
			mark[a[i + 1]] = true;
			RES[i] = query(i, i + 1);
			if (!valid(a[i + 1] + RES[i]))
			{
				a[i] = a[i + 1] - RES[i];
				continue;
			}
			else if (!valid(a[i + 1] - RES[i]))
			{
				a[i] = a[i + 1] + RES[i];
				continue;
			}

			int cur = query(i, i + 2);
			if (cur == RES[i])
				a[i] = get_ans(a[i + 1], a[i + 2], cur);
			else if (cur == RES[i + 1])
				a[i] = get_ans(a[i + 1], a[i + 2], RES[i]);
			else
				a[i] = get_ans(a[i + 2], a[i + 1], cur);
		}
	}

	FOR(i, 1, n)
		answer(i, a[i]);
}

signed main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// #define TASK "TEST"
	// if (fopen(TASK".INP", "r"))
	// {
	// 	freopen(TASK".INP", "r", stdin);
	// 	freopen(TASK".OUT", "w", stdout);
	// }
	cin >> n;
	solve(n);
	return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccjhr3U8.o: in function `query(int, int)':
grader.cpp:(.text+0x0): multiple definition of `query(int, int)'; /tmp/ccsKPw4a.o:xylophone.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccjhr3U8.o: in function `answer(int, int)':
grader.cpp:(.text+0xa0): multiple definition of `answer(int, int)'; /tmp/ccsKPw4a.o:xylophone.cpp:(.text+0x150): first defined here
/usr/bin/ld: /tmp/ccjhr3U8.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccsKPw4a.o:xylophone.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status