QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181206#6303. Inversionykpcx#WA 2ms19444kbC++171.5kb2023-09-16 16:37:482023-09-16 16:37:49

Judging History

你现在查看的是最新测评结果

  • [2023-09-16 16:37:49]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:19444kb
  • [2023-09-16 16:37:48]
  • 提交

answer

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

const int N = 2e3 + 5;

int n;
int len;
int a[N];
int vis[N][N];

int query(int l, int r) {
  if (l == r) return 0;
  if (~vis[l][r]) return vis[l][r];
  printf("? %d %d\n", l, r);
  fflush(stdout);
  int x;
  cin >> x;
  return vis[l][r] = x;
}

int cmp(int l, int r) {
  if (r - l == 1) {
    return (query(l, r) ? 1 : -1);
  }

  int left = query(l, r - 1);
  int right = query(l + 1, r);
  int mid = query(l + 1, r - 1);
  int rkl = left - mid;
  int len = r - l + 1;
  int rkr = len - (right - mid);
  if (rkl != rkr) return rkl > rkr ? 1 : -1;
  int all = query(l, r);
  return (left ^ right ^ mid ^ all ? 1 : -1);
}

void insert(int idx, int x) {
  len++;
  int i = len - 1;
  for (;i != idx; i--) a[i] = a[i-1];
  a[i] = x;
}

void solve() {
  cin >> n;
  memset(vis, -1, sizeof(vis));
  a[0] = 1;

  len = 1;
  for (int i = 2; i <= n; i++) {
    int lb = -1, rb = len;
    while (rb - lb > 1) {
      int mid = (lb + rb) / 2;
      if (cmp(a[mid], i) == -1) 
        lb = mid;
      else
        rb = mid;
    }

    // printf("rb = %d\n", rb);
    insert(rb, i);
  }

  vector<int> ans(n + 1);
  for (int i = 0; i < n; i++) {
    ans[a[i]] = i + 1;
  }
  printf("!");
  for (int i = 1; i <= len; i++) {
    printf(" %d", ans[i]);
  }

  puts("");
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0);
  solve();

  return 0;  
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 19444kb

input:

3
0
1

output:

? 1 2
? 2 3
! 1 3 2

result:

wrong answer Wa.