#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
// ordered set whith s.order_of_key(x) method, which returns rank of element x in set s
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
// pair printing
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "(" << par.first << "; " << par.second << ")"; return out;}
// set printing
template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; }
// map printing
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; }
// unordered_set printing
template <class T>
ostream& operator<<(ostream& out, const unordered_set<T> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;}
// unordered_map printing
template <class T, class U>
ostream& operator<<(ostream& out, const unordered_map<T, U> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;}
// vector printing
template<class T>
ostream& operator<<(ostream& out, const vector<T> &cont){ out << "["; for (const auto &x:cont) out << x << ", "; out << "]"; return out;}
#define print(x) cout << (x) << endl;
#define dmp(x) cerr << #x << " = " << x << endl
#define dmpn(x) cerr << #x << " = " << x << "; "
#define dmpl(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << x << endl
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define pb push_back
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define contains(s,x) ((s).find(x) != (s).end())
const int MOD = 998244353;
int U = 1, V = 15;
map<int, vector<bitset<32>>> components;
bool my_query(int a_sz, int b_sz, vector<int> &a, vector<int> &b) {
// dmpn(a); dmp(b);
if (find(all(a), U) != end(a) && find(all(b), V) != end(b)) return true;
if (find(all(a), V) != end(a) && find(all(b), U) != end(b)) return true;
return false;
}
int find_comp(int k) {
for (auto kv : components) if (find(all(kv.ss), k) != end(kv.ss)) return kv.ff;
}
int bin_search(vector<int> &a, vector<int> &b) {
int l = 0, r = sz(a) - 1;
while (l < r) {
int mid = (l + r) / 2;
vector<int> left(begin(a) + l, begin(a) + mid + 1);
bool ans = query(sz(left), sz(b), left.data(), b.data());
if (ans) r = mid;
else l = mid + 1;
// dmpn(l); dmp(r);
}
return a[l];
}
void run(int N) {
int K = 32 - __builtin_clz(N);
for (int i = 1; i <= N; i++) components[i].pb(i);
for (int t = 0; t < N - 1; t++) {
bitset<32> xr;
for (int i = 0; i < K; i++) {
// makes split according to i-th bit
pair<vector<int>, vector<int>> p;
for (int j = 1; j <= N; j++) if (!components[j].empty()) {
if (bitset<32>(j)[i]) p.ff.pb(j);
else p.ss.pb(j);
}
// bool ans = my_query(sz(p.ff), sz(p.ss), p.ff, p.ss);
bool ans = query(sz(p.ff), sz(p.ss), p.ff.data(), p.ss.data());
xr[i] = ans;
}
vector<int> nodes, comps;
for (int i = 1; i <= N; i++) if (!components[i].empty()) {
int j = i ^ xr.to_ulong();
if (components[j].empty() || j > i) continue;
comps.pb(j);
for (bitset<32> a : components[i]) nodes.pb(int(a.to_ulong()));
}
int a = bin_search(nodes, comps);
vector<int> v_a = { a };
nodes.clear();
for (auto b : components[find_comp(a ^ xr.to_ulong())]) nodes.pb(int(b.to_ulong()));
int b = bin_search(nodes, v_a);
int a_comp = find_comp(a), b_comp = find_comp(b);
for (auto x : components[b_comp]) components[a_comp].pb(x);
components[b].clear();
setRoad(a, b);
}
}
/*
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
run(15);
// cin >> t;
while (t--) {
// solve();
}
}
*/
Compilation message
icc.cpp: In function 'int find_comp(int)':
icc.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
60 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
408 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
The query sets must be disjoint |
2 |
Halted |
0 ms |
0 KB |
- |