QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#181117#6303. Inversionykpcx#WA 54ms4040kbC++171.2kb2023-09-16 15:52:242023-09-16 15:52:26

Judging History

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

  • [2023-09-16 15:52:26]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:4040kb
  • [2023-09-16 15:52:24]
  • 提交

answer

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

using namespace std;

const int N = 2e3 + 5;

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

int query(int l, int r) {
  printf("? %d %d\n", l, r);
  fflush(stdout);
  int x;
  cin >> x;
  return 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 all = query(l, r);
  return left ^ right ^ mid ^ all ? 1 : -1;
}

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

void solve() {
  cin >> n;
  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;  
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 4040kb

input:

3
0
0
1
0
0

output:

? 1 2
? 1 2
? 2 3
? 2 2
? 1 3
! 2 3 1

result:

ok OK, guesses=5

Test #2:

score: -100
Wrong Answer
time: 54ms
memory: 3752kb

input:

1993
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
1
0
0
0
0
0
0
1
0
0
1
0
0
0
1
0
0
0
1
1
0
0
0
1
0
1
0
0
1
0
1
1
0
1
1
1
0
1
1
1
1
0
1
1
1
1
1
0
1
0
1
1
0
1
1
1
0
0
0
0
1
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
1
0
1
0
1
0
1
1
0
0
1
1
1
0
1
0
1
1
1
0
1
1
1
0
1
0
1
0
1
0
1
1
1
1
1...

output:

? 1 2
? 1 2
? 2 3
? 2 2
? 1 3
? 2 3
? 2 3
? 3 4
? 3 3
? 2 4
? 3 4
? 2 4
? 3 5
? 3 4
? 2 5
? 1 4
? 2 5
? 2 4
? 1 5
? 2 5
? 3 6
? 3 5
? 2 6
? 5 6
? 1 5
? 2 6
? 2 5
? 1 6
? 1 6
? 2 7
? 2 6
? 1 7
? 5 6
? 6 7
? 6 6
? 5 7
? 1 7
? 2 8
? 2 7
? 1 8
? 3 7
? 4 8
? 4 7
? 3 8
? 2 7
? 3 8
? 3 7
? 2 8
? 1 8
? 2 9
...

result:

wrong output format Unexpected end of file - int32 expected