#include "icc.h"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
// #define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define all(x) x.begin(), x.end()
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 105;
// void setRoad(int x, int y)
// {
// cout << '!' << endl;
// cout << x << ' ' << y << endl;
// }
// int query(int n, int m, int a[], int b[])
// {
// cout << '?' << endl;
// // cout << n << ' ' << m << endl;
// for (int i = 0; i < n; i++)
// cout << a[i] << ' ';
// cout << endl;
// for (int i = 0; i < m; i++)
// cout << b[i] << ' ';
// cout << endl;
// int res;
// cin >> res;
// return res;
// }
int query(vector<int>& a, vector<int>& b)
{
int A[a.size()], B[b.size()];
for (int i = 0; i < a.size(); i++)
A[i] = a[i];
for (int i = 0; i < b.size(); i++)
B[i] = b[i];
return query((int)a.size(), (int)b.size(), A, B);
}
int BS(vector<int> a, vector<int>& b)
{
shuffle(a.begin(), a.end(), hdp);
int l = 1, r = a.size();
while (l < r)
{
int m = l + r >> 1;
vector<int> t(a.begin(), a.begin() + m);
if (query(t, b))
r = m;
else
l = m + 1;
}
return a[r - 1];
}
int id[NM], p[NM];
vector<int> v[NM];
set<int> s, did;
vector<int> a, b;
int find(int x)
{
return p[x] == x ? x : find(p[x]);
}
void merge(int x, int y)
{
x = find(x), y = find(y);
if (v[x].size() < v[y].size())
swap(x, y);
p[y] = x;
s.erase(y);
for (int t : v[y])
v[x].push_back(t);
}
void run(int N)
{
iota(p + 1, p + 1 + N, 1);
for (int i = 1; i <= N; i++)
{
v[i].push_back(i);
s.insert(i);
}
for (int n = N; n >= 2; n--)
{
auto it = s.begin();
for (int i = 1; i <= n; i++, it = next(it))
id[i] = *it;
shuffle(id + 1, id + 1 + n, hdp);
for (int i = 0; i < 7; i++)
{
a.clear(); b.clear();
for (int j = 0; j < n; j++)
for (auto t : v[id[j + 1]])
{
if (j >> i & 1)
a.push_back(t);
else
b.push_back(t);
}
if (a.size() && b.size() && query(a, b))
break;
}
int x = BS(a, b), y = BS(b, a);
setRoad(x, y);
merge(x, y);
}
}
// int main()
// {
// int N;
// cin >> N;
// run(N);
// }
Compilation message
icc.cpp: In function 'int query(std::vector<int>&, std::vector<int>&)':
icc.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
icc.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < b.size(); i++)
| ~~^~~~~~~~~~
icc.cpp: In function 'int BS(std::vector<int>, std::vector<int>&)':
icc.cpp:61:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int m = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
448 KB |
Ok! 100 queries used. |
2 |
Correct |
5 ms |
640 KB |
Ok! 99 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
648 KB |
Ok! 521 queries used. |
2 |
Correct |
30 ms |
604 KB |
Ok! 647 queries used. |
3 |
Correct |
32 ms |
640 KB |
Ok! 637 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
640 KB |
Ok! 1372 queries used. |
2 |
Correct |
97 ms |
644 KB |
Ok! 1595 queries used. |
3 |
Correct |
83 ms |
604 KB |
Ok! 1491 queries used. |
4 |
Correct |
87 ms |
440 KB |
Ok! 1484 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
632 KB |
Ok! 1500 queries used. |
2 |
Correct |
95 ms |
604 KB |
Ok! 1478 queries used. |
3 |
Correct |
91 ms |
652 KB |
Ok! 1582 queries used. |
4 |
Correct |
87 ms |
632 KB |
Ok! 1451 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
652 KB |
Ok! 1574 queries used. |
2 |
Correct |
87 ms |
648 KB |
Ok! 1554 queries used. |
3 |
Correct |
101 ms |
648 KB |
Ok! 1612 queries used. |
4 |
Correct |
82 ms |
648 KB |
Ok! 1576 queries used. |
5 |
Correct |
78 ms |
604 KB |
Ok! 1451 queries used. |
6 |
Correct |
96 ms |
600 KB |
Ok! 1498 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
656 KB |
Ok! 1580 queries used. |
2 |
Correct |
131 ms |
640 KB |
Ok! 1602 queries used. |