QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#312793 | #4831. Eager Sorting | tuanlinh123 | 0 | 1ms | 3808kb | C++20 | 1.9kb | 2024-01-24 12:09:38 | 2024-01-24 12:09:39 |
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;
};
if (!Swap(M, M+1)) return;
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)
{
vector <pll> rann;
if (ran.size()==1)
{
cout << "-1 -1" << endl;
exit(0);
}
for (ll i=ran.size()%2; 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: 3808kb
Interactor to First Run
5 0 1 0 1 1 0 0
First Run to Interactor
1 2 2 3 3 4 4 5 3 4 2 3 4 3 -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: 3808kb
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: 0ms
memory: 3520kb
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: 3568kb
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: 100
Accepted
time: 1ms
memory: 3588kb
Interactor to First Run
9 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 1
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 4 5 5 4 5 6 7 8 6 7 4 6 5 6 7 6 7 8 -1 -1
Interactor to Second Run
9 0 0 1 0 0 0 0 0 1 1 0 0
Second Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 2 3 1 2 2 4 3 4 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #6:
score: 100
Accepted
time: 1ms
memory: 3612kb
Interactor to First Run
9 0 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 2 3 3 2 4 5 7 8 6 7 5 6 4 5 6 5 6 7 -1 -1
Interactor to Second Run
9 1 1 1 0 0 0 0 0 0
Second Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 2 3 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #7:
score: 100
Accepted
time: 1ms
memory: 3572kb
Interactor to First Run
6 1 0 1 1 1 1 1 1 0 1 0 1 0 1
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 2 3 1 2 4 5 5 4 3 4 1 3 2 3 3 5 4 5 -1 -1
Interactor to Second Run
6 0 0 0 0 0
Second Run to Interactor
1 2 2 3 3 4 4 5 5 6 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #8:
score: 100
Accepted
time: 1ms
memory: 3756kb
Interactor to First Run
20 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 1 0 1 0 1 0 1 1 1 1 1 0 1 1 0 1 0 0 1 1 1 0
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 2 3 3 2 5 6 4 5 6 5 7 8 9 10 11 12 12 11 13 14 14 13 15 16 16 15 16 17 18 19 3 4 2 3 4 3 4 5 5 6 8 9 7 8 9 8 9 10 12 13 11 12 12 14 13 14 17 18 15 17 17 19 17 16 17 19 18 19 6 7 2 6 3 6 4 6 6 8 6 5 6 8 8...
Interactor to Second Run
20 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Second Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 2 3 4 5 6 7 5 6 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #9:
score: 0
Wrong Answer
time: 1ms
memory: 3808kb
Interactor to First Run
15 0 0 0 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 1 1 1
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 4 5 6 7 8 9 11 12 12 11 13 14 14 13 7 8 6 7 8 7 8 9 12 13 11 12 12 14 14 13 10 11 6 10 10 12 10 7 12 13 12 8 13 14 13 9 10 14 12 14 12 11 13 14 13 12 14 13 -1 -1
Interactor to Second Run
15 0 0 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0
Second Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 4 5 3 4 5 4 6 7 8 9 7 8 -1 -1
Manager to Checker
WA array is not sorted!
result:
wrong answer WA