QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210105 | #5531. ICC | Camillus | 100 ✓ | 72ms | 4392kb | C++20 | 4.2kb | 2023-10-11 01:32:46 | 2024-07-01 04:28:38 |
Judging History
answer
#include "bits/stdc++.h"
#include "icc.h"
using namespace std;
struct dsu {
vector<int> p;
vector<vector<int>> d;
dsu(int n) {
p.resize(n);
d.resize(n);
for (int i = 0; i < n; i++) {
p[i] = i;
d[i] = {i};
}
}
int get(int u) {
if (u == p[u]) {
return u;
} else {
return p[u] = get(p[u]);
}
}
void join(int u, int v) {
u = get(u);
v = get(v);
if (u == v) {
return;
}
if (d[v].size() > d[u].size()) {
swap(u, v);
}
p[v] = u;
d[u].insert(d[u].end(), d[v].begin(), d[v].end());
d[v].clear();
}
};
random_device rd;
mt19937 rnd(rd());
int rand(int n) {
return rnd() % n;
}
int rand(int l, int r) {
return l + rand(r - l + 1);
}
vector<int> low_half(const vector<int> &A) {
size_t x = A.size() >> 1;
return vector<int>(A.begin(), A.begin() + x);
}
vector<int> top_half(const vector<int> &A) {
size_t x = A.size() >> 1;
return vector<int>(A.begin() + x, A.end());
}
bool query(vector<int> A, vector<int> B) {
return query(A.size(), B.size(), A.data(), B.data());
}
//void setRoad(int u, int v) {
// cout << "! " << u << " " << v << endl;
//}
void run(int n) {
dsu Q(n + 1);
auto loop = [&]() {
map<int, vector<int>> A;
for (int u = 1; u <= n; u++) {
A[Q.get(u)].push_back(u);
}
vector<vector<int>> B;
B.reserve(A.size());
for (const auto &[a, b] : A) {
B.push_back(b);
}
int m = (int)B.size();
auto get = [&](const vector<int> &p) -> vector<int> {
vector<int> Q;
for (int i : p) {
Q.insert(Q.end(), B[i].begin(), B[i].end());
}
return Q;
};
int x = 0;
vector<int> x0, x1;
for (int i = 0; i <= __lg(m); i++) {
vector<int> p0, p1;
for (int j = 0; j < m; j++) {
if (bitset<32>(j)[i] == 0) {
p0.push_back(j);
} else {
p1.push_back(j);
}
}
if (query(get(p0), get(p1))) {
x1.push_back(i);
x ^= 1 << i;
} else {
x0.push_back(i);
}
}
int u = 0;
for (int i : x0) {
vector<int> p0, p1;
for (int j = 0; j < m; j++) {
if (bitset<32>(j)[i] == 1 && bitset<32>(j)[x1.front()] == 0) {
p0.push_back(j);
}
if (bitset<32>(j)[i] == 1 && bitset<32>(j)[x1.front()] == 1) {
p1.push_back(j);
}
}
if (query(get(p0), get(p1))) {
u |= 1 << i;
}
}
for (int i : x1) {
if (i == x1.front()) {
continue;
}
vector<int> p0, p1;
for (int j = 0; j < m; j++) {
if (bitset<32>(j)[i] == 0 && bitset<32>(j)[x1.front()] == 0) {
p0.push_back(j);
}
if (bitset<32>(j)[i] == 1 && bitset<32>(j)[x1.front()] == 1) {
p1.push_back(j);
}
}
if (!query(get(p0), get(p1))) {
u ^= 1 << i;
}
}
int v = x ^ u;
auto a = get({u});
auto b = get({v});
while (b.size() != 1) {
if (query(a, low_half(b))) {
b = low_half(b);
} else {
b = top_half(b);
}
}
while (a.size() != 1) {
if (query(low_half(a), b)) {
a = low_half(a);
} else {
a = top_half(a);
}
}
setRoad(a.front(), b.front());
Q.join(a.front(), b.front());
};
for (int i = 0; i < n - 1; i++) {
loop();
}
}
//
//int main() {
// int n;
// cin >> n;
// run(n);
//}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 0ms
memory: 4328kb
input:
1 1500 3 15 0 2 0.0 2.5 0 3.5 0 1 1
output:
3 Ok! 123 queries used.
result:
ok
Test #2:
score: 0
Accepted
time: 4ms
memory: 4180kb
input:
1 1500 4 15 0 0 0.0 3.5 0 2.5 5 1 1
output:
4 Ok! 122 queries used.
result:
ok
Subtask #2:
score: 11
Accepted
Test #3:
score: 11
Accepted
time: 22ms
memory: 4296kb
input:
1 2500 4 50 0 0 0.0 3.5 0 2.5 5 1 1
output:
4 Ok! 659 queries used.
result:
ok
Test #4:
score: 0
Accepted
time: 17ms
memory: 4188kb
input:
1 2500 4 50 0 1.3 0.0 0.7 0 3.5 15 2 1
output:
4 Ok! 648 queries used.
result:
ok
Test #5:
score: 0
Accepted
time: 21ms
memory: 4220kb
input:
1 2500 3 50 0.05 2.3 0.1 0.7 0 1.5 1.7 2 1
output:
3 Ok! 659 queries used.
result:
ok
Subtask #3:
score: 22
Accepted
Test #6:
score: 22
Accepted
time: 71ms
memory: 4228kb
input:
1 2250 6 100 0.05 2.3 0.1 0.7 0 1.5 1.7 1.1 1
output:
6 Ok! 1625 queries used.
result:
ok
Test #7:
score: 0
Accepted
time: 67ms
memory: 4316kb
input:
1 2250 6 100 0.05 1.5 0.1 1.3 0.01 1.7 0 100 1
output:
6 Ok! 1625 queries used.
result:
ok
Test #8:
score: 0
Accepted
time: 69ms
memory: 4256kb
input:
1 2250 5 100 0.00 2.00 0.00 1.70 0.10 1.30 5 1.15 1
output:
5 Ok! 1620 queries used.
result:
ok
Test #9:
score: 0
Accepted
time: 69ms
memory: 4392kb
input:
1 2250 5 100 0.00 1.00 0.00 2.30 0.00 0.70 0 1.1 1
output:
5 Ok! 1625 queries used.
result:
ok
Subtask #4:
score: 21
Accepted
Test #10:
score: 21
Accepted
time: 69ms
memory: 4264kb
input:
1 2000 5 100 0.01 1.00 0.10 1.70 0.00 1.50 5.0 1.20 1
output:
5 Ok! 1613 queries used.
result:
ok
Test #11:
score: 0
Accepted
time: 66ms
memory: 4188kb
input:
1 2000 5 100 0.00 0.70 0.00 2.10 0.00 1.20 0.0 1.5 1
output:
5 Ok! 1625 queries used.
result:
ok
Test #12:
score: 0
Accepted
time: 72ms
memory: 4248kb
input:
1 2000 6 100 0.01 0.70 0.00 2.70 0.00 1.90 3.5 1.1 1
output:
6 Ok! 1621 queries used.
result:
ok
Test #13:
score: 0
Accepted
time: 70ms
memory: 4236kb
input:
1 2000 5 100 0.01 1.00 0.10 1.70 0.01 2.30 5.0 1.20 1
output:
5 Ok! 1605 queries used.
result:
ok
Subtask #5:
score: 29
Accepted
Test #14:
score: 29
Accepted
time: 69ms
memory: 4272kb
input:
1 1775 4 100 0.00 0.00 0.00 2.70 0.10 7.55 0.0 1.15 1
output:
4 Ok! 1625 queries used.
result:
ok
Test #15:
score: 0
Accepted
time: 67ms
memory: 4320kb
input:
1 1775 5 100 0.00 1.50 0.00 1.10 0.00 1.75 0.0 1.5 1
output:
5 Ok! 1625 queries used.
result:
ok
Test #16:
score: 0
Accepted
time: 68ms
memory: 4376kb
input:
1 1775 5 100 0.01 1.50 0.00 1.10 0.01 1.75 0.0 1.3 1
output:
5 Ok! 1625 queries used.
result:
ok
Test #17:
score: 0
Accepted
time: 63ms
memory: 4308kb
input:
1 1775 5 100 0.00 0.30 0.00 2.10 0.00 1.75 0.0 1.5 1
output:
5 Ok! 1625 queries used.
result:
ok
Test #18:
score: 0
Accepted
time: 67ms
memory: 4232kb
input:
1 1775 5 100 0.01 0.70 0.00 2.70 0.00 1.90 3.5 1.5 1
output:
5 Ok! 1620 queries used.
result:
ok
Test #19:
score: 0
Accepted
time: 70ms
memory: 4332kb
input:
1 1775 5 100 0.01 1.50 0.00 1.10 0.01 1.75 1.0 1.10 1
output:
5 Ok! 1625 queries used.
result:
ok
Subtask #6:
score: 10
Accepted
Test #20:
score: 10
Accepted
time: 67ms
memory: 4252kb
input:
1 1625 5 100 0.00 0.00 0.00 3.00 0.00 1.00 0.0 3 1
output:
5 Ok! 1625 queries used.
result:
ok
Test #21:
score: 0
Accepted
time: 62ms
memory: 4176kb
input:
1 1625 5 100 0.00 0.90 0.00 2.70 0.10 1.55 0.0 1.55 1
output:
5 Ok! 1625 queries used.
result:
ok