QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#877076 | #124. Library | ltunjic | 0 | 1147ms | 4096kb | C++20 | 2.8kb | 2025-01-31 19:26:36 | 2025-01-31 19:26:38 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <vector>
#include "library.h"
#include <algorithm>
#define PB push_back
using namespace std;
const int N = 2e4 + 10;
int n, un[N], l[N], r[N];
vector<int> g[N];
int trazi(int u) { return un[u] == -1 ? u : un[u] = trazi(un[u]); }
void upali(int u, vector<int> &q) {
for(int i = 0; i < n; ++i) {
if(trazi(i) == u) { q[i] = 1; }
}
}
bool kraj(int x, int u) {
vector<int> q(n, 0);
upali(u, q);
q[l[u]] = 0;
q[x] = 1;
if(Query(q) == 2) {
g[x].PB(l[u]);
g[l[u]].PB(x);
return 0;
}
g[x].PB(r[u]);
g[r[u]].PB(x);
return 1;
}
bool bio[N];
void lanac(int u, int p, vector<int> &a) {
a.PB(u + 1);
for(int v : g[u]) {
if(v != p) { lanac(v, u, a); }
}
}
void Solve(int nn) {
n = nn;
memset(un, -1, sizeof(un));
for(int i = 0; i <= n; ++i) { l[i] = r[i] = i; }
for(int i = 1; i < n; ++i) {
// printf("%d:\n", i);
// for(int j = 0; j < i; ++j) { printf("%d ", trazi(j)); } printf("\n");
vector<int> q(n, 0);
int c = 0;
memset(bio, 0, sizeof(bio));
for(int j = 0; j < i; ++j) { bio[trazi(j)] = 1; }
for(int j = 0; j < i; ++j) { if(bio[j]) { upali(j, q); ++c; } }
q[i] = 1;
int res = Query(q);
// printf("%d %d\n", res, c);
if(res != c + 1) {
int fir = -1, sec = -1, f1, f2;
int lo = -1, hi = i - 1;
// printf("%d %d\n", lo, hi);
for(int mi = (lo + hi) / 2; hi - lo > 1; mi = (lo + hi) / 2) {
fill(q.begin(), q.end(), 0);
memset(bio, 0, sizeof(bio));
int c2 = 0;
for(int j = 0; j <= mi; ++j) { bio[trazi(j)] = 1; }
for(int j = 0; j < i; ++j) { if(bio[j]) { upali(j, q); ++c2; } }
q[i] = 1;
int res2 = Query(q);
if(res2 == c2 + 1) {
lo = mi;
} else {
hi = mi;
}
}
fir = trazi(hi);
// printf("fir %d\n", fir);
f1 = kraj(i, trazi(hi));
if(res != c) {
int lo2 = -1, hi2 = i - 1;
for(int mi = (lo2 + hi2) / 2; hi2 - lo2 > 1; mi = (lo2 + hi2) / 2) {
fill(q.begin(), q.end(), 0);
memset(bio, 0, sizeof(bio));
int c2 = 0;
for(int j = 0; j <= mi; ++j) { bio[trazi(j)] = 1; }
bio[fir] = 0;
for(int j = 0; j < i; ++j) { if(bio[j]) { upali(j, q); ++c2; } }
q[i] = 1;
int res2 = Query(q);
if(res2 == c2 + 1) {
lo2 = mi;
} else {
hi2 = mi;
}
}
sec = trazi(hi2);
// printf("sec %d %d\n", sec, hi2);
f2 = kraj(i, trazi(hi2));
}
if(sec == -1) {
un[i] = fir;
if(f1) { r[fir] = i; }
else { l[fir] = i; }
} else {
un[i] = fir;
un[sec] = i;
if(f1) { l[fir] = l[sec]; }
else { r[fir] = r[sec]; }
}
}
}
vector<int> ans;
for(int i = 0; i < n; ++i) {
if(g[i].size() == 1) { lanac(i, -1, ans); break; }
}
Answer(ans);
return;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 3968kb
input:
192 17 6 145 10 132 34 129 8 137 157 65 54 138 85 60 190 52 75 179 23 167 41 117 186 165 26 111 73 49 92 3 81 96 11 152 45 56 33 182 15 130 166 105 19 158 159 156 149 169 153 106 134 114 148 124 80 28 68 184 62 104 67 150 128 175 116 144 183 189 151 173 39 108 71 79 5 47 99 162 163 177 69 20 136 82 ...
output:
Wrong Answer [8]
result:
wrong answer
Subtask #2:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 1147ms
memory: 4096kb
input:
1000 972 265 212 27 724 465 50 304 37 134 246 257 177 482 90 974 616 221 151 912 946 366 590 277 187 976 394 765 643 740 385 665 749 585 923 92 920 994 48 405 978 893 477 381 788 992 825 680 785 297 679 116 836 31 333 714 828 922 492 890 919 237 188 677 557 522 867 368 19 690 29 632 832 17 107 485 3...
output:
Wrong Answer [8]
result:
wrong answer