QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#312706#4831. Eager Sortingminhnhatnoe0 1ms3636kbC++141000b2024-01-24 10:59:222024-01-24 10:59:22

Judging History

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

  • [2024-01-24 10:59:22]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3636kb
  • [2024-01-24 10:59:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n;

int inter(int i, int j){
    if (i == j) return 0;
    if (i > j) swap(i, j);
    cout << i+1 << " " << j+1 << endl;
    int v; cin >> v;
    if (v == -1) exit(0);
    return v;
}

void trip(int pos, int c1, int c2){
    assert(pos < c1 && c1 < c2);
    inter(c1, c2);
    inter(pos, c1);
}

void recurse(int begin, int end){
    if (begin+1 == end) return;

    int mid = (begin + end)>>1;
    recurse(begin, mid);
    recurse(mid, end);

    int ptrl = begin, ptrr = mid;
    while (true){
        int v = inter(ptrl, ptrr);
        ptrl++;
        if (v) break;
        if (ptrl == mid) return;
    }

    while (ptrl != mid){
        trip(ptrl, ptrr, ptrr+1);
        ptrl++;
    }
    
    while (ptrr+1 != end){
        int v = inter(ptrr, ptrr+1);
        if (v == 0) break;
        ptrr++;
    }
}

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    recurse(0, n);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

Interactor to First Run

5
0
1
0
1
0
1
1
0
-1

First Run to Interactor

1 2
4 5
3 4
1 3
3 4
2 3
3 4
4 5

Interactor to Second Run

5
0
0
0
0
0

Second Run to Interactor

1 2
4 5
3 4
1 3
2 3

Manager to Checker

OK
good job!

result:

ok OK

Test #2:

score: 0
Instance #1 Memory Limit Exceeded

Interactor to First Run

1

First Run to Interactor


Interactor to Second Run


Second Run to Interactor


Manager to Checker

WA
Invalid Operation 798391512 21959

result: