Submission #827856

# Submission time Handle Problem Language Result Execution time Memory
827856 2023-08-16T20:23:45 Z themm1 ICC (CEOI16_icc) C++17
0 / 100
2 ms 468 KB
#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 N, K;
int U, V;
vector<pii> solution;
vector<unordered_set<int>> g;
map<int, vector<bitset<32>>> components;

bool my_query(int a_sz, int b_sz, vector<int> &a, vector<int> &b) {
        unordered_set<int> s;
        for (int u : a) {
                if (s.count(u)) print("non-disjoint query");
                s.insert(u);
        }
        for (int u : b) {
                if (s.count(u)) print("non-disjoint query");
                s.insert(u);
        }
        for (int u : a) for (int v : b) if (g[u].count(v)) 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;
        return -1;
}

int bin_search_node(vector<int> &a, vector<int> &b) {
        // dmpn(a); dmp(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 = my_query(sz(left), sz(b), left, b);
                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];
}

int find_xor() {
        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++) for (auto k : components[j]) {
                        if (bitset<32>(j)[i]) p.ff.pb(k.to_ulong());
                        else p.ss.pb(k.to_ulong());
                }
                // 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;
        }
        return xr.to_ulong();
}

void run(int n) {
        N = n;
        g.resize(N + 1);
	K = 32 - __builtin_clz(N);
	for (int i = 1; i <= N; i++) components[i].pb(i);

	for (int t = 0; t < N - 1; t++) {
                /*
                U = solution[t].ff, V = solution[t].ss;
                g[U].insert(V);
                g[V].insert(U);
                */

                int xr = find_xor();
                vector<int> nodes_a, nodes_b;
                for (int i = 1; i <= N; i++) if (!components[i].empty()) {
                        int j = i ^ xr;
                        if (components[j].empty() || j > i) continue;
                        for (bitset<32> a : components[i]) nodes_a.pb(int(a.to_ulong()));
                        for (bitset<32> a : components[j]) nodes_b.pb(int(a.to_ulong()));
                }
                int a = bin_search_node(nodes_a, nodes_b);
                vector<int> v_a;
                for (bitset<32> b : components[find_comp(a)]) v_a.pb(b.to_ulong());
                nodes_a.clear();
                for (auto b : components[find_comp(a ^ xr)]) nodes_a.pb(int(b.to_ulong()));
                int b = bin_search_node(nodes_a, 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_comp].clear();
                g[a].insert(b);
                g[b].insert(a);
                /*
                cout << a << " " << b << endl;
                if (make_pair(a, b) != solution[t] && make_pair(b, a) != solution[t]) {
                        cout << "WA" << endl;
                        dmp(solution[t]);
                        while (true) {};
                }
                */
                setRoad(a + 1, b + 1);
	}
}

/*
void solve() {
        int N;
        cin >> N;
        for (int i = 0; i < N - 1; i++) {
                int a, b;
                cin >> a >> b;
                solution.pb({ a, b });
        }
        run(N);
}

int32_t main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);

        int t = 1;
        // cin >> t;
        while (t--) {
                solve();
        }
}
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Wrong road!
2 Halted 0 ms 0 KB -