## \(\color{#0066ff}{ 题目描述 }\)

lzxkj一向很好奇，他想要知道这个排列是什么，但是由于lzxkj和阿习小pen友一起来的，的花_Q就是不告诉他。

get_permutation(N, ans)

void get_permutation(int N, int ans[]);

int query(int l, int r);

g++ grader.cpp permutation.cpp -o permutation -O2 -lm

## \(\color{#0066ff}{输入样例}\)

``````5
0 3 2 4 1``````

## \(\color{#0066ff}{输出样例}\)

``Correct``

## \(\color{#0066ff}{ 题解 }\)

#### 就没了

``````#include"permutation.h"
#include<cstdio>
#include<iostream>

#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int maxn = 5010;
bool flag;
int n;
int abs(int x) { return x > 0? x : -x; }
void get_permutation(int N, int ans[]) {
ans[0] = 0;
ans[1] = query(0, 1);
for(int i = 2; i < N; i++) {
int t1 = query(i - 2, i);
int t2 = query(i - 1, i);
int a = ans[i - 1] + t2;
int b = ans[i - 1] - t2;
if(t1 == abs(ans[i - 1] - ans[i - 2])) {
if(a >= std::min(ans[i - 1], ans[i - 2]) && a <= std::max(ans[i - 1], ans[i - 2])) ans[i] = a;
else ans[i] = b;
}
else if(t1 == t2) {
if(ans[i - 1] > ans[i - 2]) ans[i] = b;
else ans[i] - a;
}
else {
if(ans[i - 1] > ans[i - 2]) ans[i] = a;
else ans[i] = b;
}
}
int min = 0x7fffffff;
for(int i = 0; i < N; i++) min = std::min(min, ans[i]);
for(int i = 0; i < N; i++) ans[i] -= min;
int pos0, posn;
for(int i = 0; i < N; i++) {
if(ans[i] == 0) pos0 = i;
if(ans[i] == N - 1) posn = i;
}
if(pos0 > posn) for(int i = 0; i < N; i++) ans[i] = N - 1 - ans[i];
}``````

0条评论