#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll , ll> ii;
#define ff first
#define ss second
#define pb push_back
#define in insert
ll Q(vector < ll > a, vector < ll > b){
if(min(a.size(), b.size()) == 0) return 0;
ll sz1 = a.size(); ll A[sz1];
ll sz2 = b.size(); ll B[sz2];
for(ll i = 0; i < sz1; i++) A[i] = a[i];
for(ll i = 0; i < sz2; i++) B[i] = b[i];
return query(sz1,sz2,A,B);
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
struct DSU{
vector < int > par;
void start(int n){
par.resize(n + 1);
for(int i = 0; i <= n; i++) par[i] = i;
}
int find(int a){
if(a == par[a]) return a;
return par[a] = find(par[a]);
}
void merge(int x, int y){
x = find(x); y = find(y);
if(x == y) return;
if(rng()&1) swap(x,y);
par[x] = y;
return;
}
}T;
void run(int n) {
T.start(n);
for(ll itr = 1; itr < n; itr++){
vector < ll > bit = {0,1,2,3,4,5,6};
//shuffle(bit.begin(), bit.end(), rng);
vector < ll > A,B;
vector < ll > idx;
for(ll i = 1; i <= n; i++){
idx.pb(T.find(i));
}
sort(idx.begin(), idx.end());
idx.erase(unique(idx.begin(), idx.end()), idx.end());
vector < ll > p(idx.size());
for(ll i = 0; i < p.size(); i++) p[i] = i;
shuffle(p.begin(), p.end(), rng);
for(auto j : bit){
A.clear();
B.clear();
for(ll i = 1; i <= n; i++){
ll k = lower_bound(idx.begin(), idx.end(), T.find(i)) - idx.begin();
k = p[k];
if((k >> j)&1) A.pb(i);
else B.pb(i);
}
if(Q(A,B)) break;
}
while(A.size() > 1){
shuffle(A.begin(), A.end(), rng);
ll m = A.size()/2;
vector < ll > v1, v2;
for(ll i = 0; i < m; i++) v1.pb(A[i]);
for(ll i = m; i < A.size(); i++) v2.pb(A[i]);
if(Q(v1, B)) A = v1;
else A = v2;
}
while(B.size() > 1){
ll m = B.size()/2;
vector < ll > v1, v2;
for(ll i = 0; i < m; i++) v1.pb(B[i]);
for(ll i = m; i < B.size(); i++) v2.pb(B[i]);
if(Q(A, v1)) B = v1;
else B = v2;
}
setRoad(A[0], B[0]);
T.merge(A[0], B[0]);
}
}
Compilation message
icc.cpp: In function 'void run(int)':
icc.cpp:62:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(ll i = 0; i < p.size(); i++) p[i] = i;
| ~~^~~~~~~~~~
icc.cpp:82:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(ll i = m; i < A.size(); i++) v2.pb(A[i]);
| ~~^~~~~~~~~~
icc.cpp:90:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(ll i = m; i < B.size(); i++) v2.pb(B[i]);
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
496 KB |
Ok! 98 queries used. |
2 |
Correct |
10 ms |
468 KB |
Ok! 97 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
476 KB |
Ok! 542 queries used. |
2 |
Correct |
42 ms |
468 KB |
Ok! 689 queries used. |
3 |
Correct |
39 ms |
468 KB |
Ok! 678 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
488 KB |
Ok! 1430 queries used. |
2 |
Correct |
141 ms |
492 KB |
Ok! 1662 queries used. |
3 |
Correct |
126 ms |
496 KB |
Ok! 1581 queries used. |
4 |
Correct |
115 ms |
500 KB |
Ok! 1528 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
500 KB |
Ok! 1545 queries used. |
2 |
Correct |
129 ms |
488 KB |
Ok! 1527 queries used. |
3 |
Correct |
130 ms |
488 KB |
Ok! 1636 queries used. |
4 |
Correct |
118 ms |
500 KB |
Ok! 1466 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
147 ms |
500 KB |
Ok! 1632 queries used. |
2 |
Correct |
140 ms |
504 KB |
Ok! 1643 queries used. |
3 |
Correct |
130 ms |
496 KB |
Ok! 1648 queries used. |
4 |
Correct |
130 ms |
500 KB |
Ok! 1610 queries used. |
5 |
Correct |
123 ms |
488 KB |
Ok! 1518 queries used. |
6 |
Correct |
141 ms |
488 KB |
Ok! 1586 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
137 ms |
496 KB |
Too many queries! 1637 out of 1625 |
2 |
Halted |
0 ms |
0 KB |
- |