QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#742214 | #9432. Permutation | Sktn0089 | TL | 1ms | 8020kb | C++14 | 2.0kb | 2024-11-13 16:06:19 | 2024-11-13 16:06:19 |
Judging History
answer
#include <bits/stdc++.h>
#define ll int
#define fi first
#define se second
#define mkp make_pair
#define pir pair <ll, ll>
#define pb emplace_back
#define i128 __int128
using namespace std;
const ll maxn = 2e6 + 10, inf = 1e9;
ll n, a[maxn], b[maxn], id[maxn];
ll query() {
printf("0");
for(ll i = 1; i <= n; i++) printf(" %d", b[i]);
puts(""), fflush(stdout);
ll x; scanf("%d", &x); return x;
}
void solve(ll l, ll r, ll c) {
if(l == r) { a[l] = c; return; }
ll mid = l + r >> 1;
ll e = c == 1? 2 : 1;
for(ll i = 1; i <= n; i++)
if(mid < i && i <= r) b[i] = e;
else b[i] = c;
if(query()) solve(l, mid, c);
else solve(mid + 1, r, c);
}
void work(ll p, ll q) {
ll l = 1, r = n;
ll lp, rp, lq, rq;
ll e = min(p, q) > 1? 1 : (max(p, q) == 2? 3 : 2);
while(l < r) {
ll mid = l + r >> 1;
for(ll i = 1; i <= n; i++)
if(i > mid && i <= r) b[i] = q;
else b[i] = p;
ll tmp = query();
if(tmp == 0) {
lp = mid + 1, rp = r;
lq = l, rq = mid; break;
}
if(tmp == 2) {
lp = l, rp = mid;
lq = mid + 1, rq = r; break;
}
for(ll i = mid + 1; i <= r; i++) b[i] = e;
if(query()) r = mid;
else l = mid + 1;
}
while(lp < rp && lq < rq) {
ll midp = lp + rp >> 1, midq = lq + rq >> 1;
for(ll i = 1; i <= n; i++)
if(midp < i && i <= rp || lq <= i && i <= midq)
b[i] = q;
else b[i] = p;
ll tmp = query();
if(tmp == 0)
lp = midp + 1, lq = midq + 1;
else if(tmp == 2)
rp = midp, rq = midq;
else {
for(ll i = lq; i <= midq; i++) b[i] = p;
if(query()) rp = midp, lq = midq + 1;
else lp = midp + 1, rq = midq;
}
}
solve(lp, rp, p);
solve(lq, rq, q);
}
int main() {
scanf("%d", &n); srand(time(0));
for(ll i = 1; i <= n; i++) id[i] = i;
random_shuffle(id + 1, id + 1 + n);
for(ll i = 1; 2 * i <= n; i++)
work(id[2 * i], id[2 * i - 1]);
if(n & 1) {
for(ll i = 1; i <= n; i++)
if(!a[i]) a[i] = id[n];
} printf("1 ");
for(ll i = 1; i <= n; i++) printf("%d ", a[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8020kb
input:
5 0 2 0 0 1 0 1
output:
0 1 1 1 4 4 0 4 4 1 1 4 0 4 1 4 4 4 0 5 5 5 3 3 0 3 3 5 5 3 0 5 5 5 5 3 0 3 1 3 3 3 1 3 4 2 1 5
result:
ok Accepted
Test #2:
score: -100
Time Limit Exceeded
input:
1000 1 0 1 1 1 0 1 1 0 2 1 0 1 0 1 0 1 0 2 2 2 2 1 1 0 1 0 0 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 441 44...