QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#312960 | #4831. Eager Sorting | duongnc000 | 0 | 1ms | 3812kb | C++20 | 2.8kb | 2024-01-24 15:05:25 | 2024-01-24 15:05:25 |
answer
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;
int pos[105];
int query(int x, int y) {
if (x == y) return 0;
cout << x << " " << y << endl;
int res; cin >> res;
if (res == -1) exit(0);
if (res == 1) swap(pos[x], pos[y]);
return res;
}
void merge(int l1, int r1, int l2, int r2) {
// cout << "merge " << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
iota(pos + l1, pos + r2 + 1, l1);
int ptr = l1, len = (r1 - l1 + 1) + (r2 - l2 + 1);
for (int i = 1; i < len; ++i) {
// cout << i << " " << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
if (l1 > r1) { query(ptr++, pos[l2++]); continue; }
if (l2 > r2) { query(ptr++, pos[l1++]); continue; }
int cpos = 0;
if (ptr == pos[l1] or query(ptr, pos[l1])) cpos = l1;
if (ptr == pos[l2] or query(ptr, pos[l2])) cpos = l2;
++ptr;
if (cpos == l1) ++l1;
else ++l2;
}
}
int n;
void solve() {
cin >> n;
if (n == 1) {
cout << -1 << " " << -1 << endl;
return;
}
vector<pair<int, int>> v;
int l = 1;
for (int i = 1; i < n; ++i) {
if (query(i, i + 1)) {
if (i > 1) v.emplace_back(l, i - 1);
l = i;
}
}
v.emplace_back(l, n - 1);
while (isz(v) > 1) {
vector<pair<int, int>> nv;
for (int i = 0; i + 1 < isz(v); i += 2) {
merge(v[i].ff, v[i].ss, v[i + 1].ff, v[i + 1].ss);
nv.emplace_back(v[i].ff, v[i + 1].ss);
}
if (isz(v) & 1) nv.emplace_back(v.back());
v.swap(nv);
}
cout << -1 << " " << -1 << endl;
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
cout << "Check array size pls sir" << endl;
#endif
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
Interactor to First Run
5 0 1 0 1 1 0 0 0 -1
First Run to Interactor
1 2 2 3 3 4 4 5 1 2 2 3 1 4 2 4 3 4
Interactor to Second Run
5 0 0 1 0 0 0
Second Run to Interactor
1 2 2 3 3 4 4 5 1 3 2 3 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #2:
score: 100
Accepted
time: 1ms
memory: 3812kb
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: 3756kb
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: 3600kb
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: 3572kb
Interactor to First Run
9 1 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 1 4 2 4 3 4 5 7 6 7 1 5 2 5 2 6 3 1 3 6 4 1 4 7 5 1 6 3 1 8 2 8 3 8 4 8 5 8 6 8 7 8 -1 -1
Interactor to Second Run
9 0 0 0 1 0 0 0 0 0 0 1 0
Second Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 1 4 2 4 3 4 4 5 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #6:
score: 100
Accepted
time: 1ms
memory: 3608kb
Interactor to First Run
9 0 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 1 0 0 0 0 0
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 1 2 3 4 5 6 1 3 2 3 2 4 3 1 3 4 5 8 6 8 7 5 1 5 2 5 3 5 4 5 -1 -1
Interactor to Second Run
9 0 0 0 0 0 0 1 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 1 7 2 7 3 7 4 7 5 7 6 7 -1 -1
Manager to Checker
OK good job!
result:
ok OK
Test #7:
score: 100
Accepted
time: 1ms
memory: 3588kb
Interactor to First Run
6 1 0 1 1 1 1 1 1 0 1 1 0 0 1
First Run to Interactor
1 2 2 3 3 4 4 5 5 6 1 3 2 3 4 5 1 4 2 4 3 4 3 5 4 2 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: 0
Wrong Answer
time: 1ms
memory: 3584kb
Interactor to First Run
20 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 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 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 18 17 18 1 3 2 3 2 4 3 5 4 5 6 8 7 8 10 12 11 12 11 13 12 10 12 13 14 16 15 16 15 17 16 18 17 18 1 6 2 6 3 6 4 6 4 7 5 6 5 8 6 9 7 9 8 9 10 14 11 14 11 15 12 14 12 16...
Interactor to Second Run
20 0 0 1 0 1 1 0 1 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1
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 1 3 2 3 5 6 8 10 9 10 11 15 12 15 13 15 14 15 1 5 2 5 3 5 4 5 5 6 8 11 9 11 10 11 11 12 1 8 2 8 3 8 4 8 5 8 6 8 7 8 7 9 8 10 9 10 1 18 2 18 3 18 4 18 5 18 6 18 7 18 8 18 9 18 10 18 11 18 11 19 12 10 12 1...
Manager to Checker
WA array is not sorted!
result:
wrong answer WA