QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#181164#6303. Inversionykpcx#WA 67ms19368kbC++171.3kb2023-09-16 16:09:162023-09-16 16:09:17

Judging History

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

  • [2023-09-16 16:09:17]
  • 评测
  • 测评结果:WA
  • 用时:67ms
  • 内存:19368kb
  • [2023-09-16 16:09:16]
  • 提交

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 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;  
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 19352kb

input:

3
0
1
0

output:

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

result:

ok OK, guesses=3

Test #2:

score: -100
Wrong Answer
time: 67ms
memory: 19368kb

input:

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

output:

? 1 2
? 2 3
? 1 3
? 3 4
? 2 4
? 3 5
? 2 5
? 1 4
? 1 5
? 3 6
? 2 6
? 5 6
? 1 6
? 2 7
? 1 7
? 6 7
? 5 7
? 2 8
? 1 8
? 3 7
? 4 8
? 4 7
? 3 8
? 2 9
? 1 9
? 8 9
? 3 9
? 9 10
? 5 9
? 6 10
? 6 9
? 5 10
? 7 9
? 8 10
? 7 10
? 1 10
? 2 11
? 2 10
? 1 11
? 9 11
? 8 11
? 10 11
? 11 12
? 9 12
? 8 12
? 10 12
? 3 1...

result:

wrong output format Unexpected end of file - int32 expected