#include "xylophone.h"
#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;
template<class A, class B>
bool maximize(A& x, B y) {
if (x < y) return x = y, true; else return false;
}
template<class A, class B>
bool minimize(A& x, B y) {
if (x > y) return x = y, true; else return false;
}
/* END OF TEMPLATE */
const int N = 5007;
int n, b[N], a[N];
int cntQuery = 0;
int query(int s, int t) {
cntQuery++;
int Max = b[s], Min = b[s];
FOR(i, s + 1, t) {
maximize(Max, b[i]);
minimize(Min, b[i]);
}
return Max - Min;
}
void answer(int i, int a) {
cout<<i<<" "<<a<<"\n";
}
int relation[N], diff[N];
int c[N], cnt[N];
vector<int> get_permutation() {
vector<int> tmp;
FOR(t, 1, n) {
c[1] = t;
FOR(i, 2, n)
if (relation[i - 1] == 0) c[i] = c[i - 1] + diff[i - 1]; else c[i] = c[i - 1] - diff[i - 1];
FOR(i, 1, n) cnt[i] = 0;
bool kt = true;
FOR(i, 1, n)
if (c[i] < 1 || c[i] > n || (++cnt[c[i]]) > 1) kt = false;
if (kt) return vector<int>(c + 1, c + 1 + n);
}
return tmp;
}
bool check(vector<int> node) {
if (node.empty()) return false;
int pos_1 = 0, pos_n = 0;
REP(i, 0, n)
if (node[i] == 1) pos_1 = i + 1; else
if (node[i] == n) pos_n = i + 1;
if (pos_1 > pos_n) return false;
return query(pos_1, pos_n) == n - 1 && query(pos_1, pos_n - 1) != n - 1;
}
void solve(int m) {
n = m;
FOR(i, 1, n) a[i] = 0, relation[i] = 0;
REP(i, 1, n) diff[i] = query(i, i + 1);
REP(i, 1, n - 1)
if (query(i, i + 2) != diff[i] + diff[i + 1]) relation[i + 1] = relation[i] ^ 1; else relation[i + 1] = relation[i];
vector<int> node = get_permutation();
// REP(i, 1, n) cout<<relation[i]<<" "; cout<<"\n";
// for (auto x : node) cout<<x<<" "; cout<<"\n";
// exit(0);
if (check(node)) {
REP(i, 0, n) a[i + 1] = node[i];
}
else {
REP(i, 1, n) relation[i]^=1;
node = get_permutation();
REP(i, 0, n) a[i + 1] = node[i];
}
FOR(i, 1, n) answer(i, a[i]);
}
Compilation message
/usr/bin/ld: /tmp/cchLzI8r.o: in function `query(int, int)':
grader.cpp:(.text+0x0): multiple definition of `query(int, int)'; /tmp/ccTPaoIr.o:xylophone.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/cchLzI8r.o: in function `answer(int, int)':
grader.cpp:(.text+0xa0): multiple definition of `answer(int, int)'; /tmp/ccTPaoIr.o:xylophone.cpp:(.text+0x60): first defined here
collect2: error: ld returned 1 exit status