QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#312779#4831. Eager Sortingtuanlinh1230 1ms3832kbC++201.9kb2024-01-24 12:00:432024-01-24 12:00:44

Judging History

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

  • [2024-01-24 12:00:44]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3832kb
  • [2024-01-24 12:00:43]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

vector <pll> ran;
ll ask(ll i, ll j)
{
    if (i==j) return 0;
    cout << i << " " << j << endl;
    ll x; cin >> x; 
    if (x==-1) exit(0);
    return x;
}

void merge(ll i)
{
    ll L=ran[i].fi, M=ran[i].se, R=ran[i+1].se;
    vector <ll> pos(R+5, 0), a(R+5, 0);
    for (ll i=1; i<=R; i++) pos[i]=a[i]=i;
    auto Swap=[&](ll i, ll j)
    {
        if (i==j) return 0;
        if (!ask(i, j)) return 0;
        swap(pos[a[i]], pos[a[j]]);
        swap(a[i], a[j]);
        return 1;
    };
    for (ll lptr=L, rptr=M+1; lptr<=M || rptr<=R;)
    {
        ll p=L+(lptr-L)+(rptr-M-1);
        if (lptr>M) Swap(pos[rptr], p), rptr++;
        else if (rptr>R) Swap(pos[lptr], p), lptr++;
        else if (pos[lptr]<pos[rptr])
        {
            if (Swap(pos[lptr], pos[rptr]))
                Swap(pos[rptr], p), rptr++;
            else Swap(pos[lptr], p), lptr++;
        }
        else
        {
            if (Swap(pos[lptr], pos[rptr]))
                Swap(pos[lptr], p), lptr++;
            else Swap(pos[rptr], p), rptr++;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, lo=1; cin >> n;
    for (ll i=2; i<=n; i++)
        if (ask(i-1, i))
        {
            if (lo<=i-2) ran.pb({lo, i-2});
            lo=i-1;
        }
    ran.pb({lo, n-1});
    while (1)
    {
        if (ran.size()==1)
        {
            cout << "-1 -1" << endl;
            exit(0);
        }
        vector <pll> rann;
        for (ll i=ran[0].se-ran[0].fi<ran.back().se-ran.back().fi?0:1; i<ran.size(); i+=2)
        {
            if (i+1==ran.size()) rann.pb(ran[i]);
            else merge(i), rann.pb({ran[i].fi, ran[i+1].se});
        }
        swap(ran, rann);
    }
}

详细

Test #1:

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

Interactor to First Run

5
0
1
0
1
0
1

First Run to Interactor

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

Interactor to Second Run

5
1
0
0
0

Second Run to Interactor

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

Manager to Checker

OK
good job!

result:

ok OK

Test #2:

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

Interactor to First Run

1

First Run to Interactor

-1 -1

Interactor to Second Run

1

Second Run to Interactor

-1 -1

Manager to Checker

OK
good job!

result:

ok OK

Test #3:

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

Interactor to First Run

2
0

First Run to Interactor

1 2
-1 -1

Interactor to Second Run

2
0

Second Run to Interactor

1 2
-1 -1

Manager to Checker

OK
good job!

result:

ok OK

Test #4:

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

Interactor to First Run

2
1

First Run to Interactor

1 2
-1 -1

Interactor to Second Run

2
0
-1

Second Run to Interactor

1 2
-1 -1

Manager to Checker

OK
good job!

result:

ok OK

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 3604kb

Interactor to First Run

9
1
0
0
1
1
0
1
1
1
0
0

First Run to Interactor

1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
4 5
5 6
7 8
-1 -1

Interactor to Second Run

9
0
0
1
0
0
1
1
0
0
0
0

Second Run to Interactor

1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
3 6
4 6
5 6
-1 -1

Manager to Checker

WA
array is not sorted!

result:

wrong answer WA