Submission #605646

# Submission time Handle Problem Language Result Execution time Memory
605646 2022-07-25T20:55:45 Z SlavicG ICC (CEOI16_icc) C++17
100 / 100
137 ms 616 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;

/*
int query(int a, int b, int* aa, int* bb) {

}
*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int query(vector<int> a, vector<int> b) {
    int aa[(int)a.size()], bb[(int)b.size()];
    for(int i = 0; i < (int)a.size(); ++i) aa[i] = a[i];
    for(int i = 0; i < (int)b.size(); ++i) bb[i] = b[i];
    return query(a.size(), b.size(), aa, bb);
}
struct dsu {
    vector<int> p, s;
    dsu(int n) {
        p.resize(n);
        s.assign(n, 1);
        iota(p.begin(), p.end(), 0);
    }
    int get(int a) {return p[a] = (p[a] == a ? a : get(p[a]));}
    int sz(int a) {return s[get(a)];}
    void uni(int a, int b) {
        a = get(a);
        b = get(b);
        if(s[a] > s[b]) swap(a, b);
        p[a] = b;
        s[b] += s[a];
    }
};

int ask(vector<int> a, vector<int> b) {
    int l = 0, r = (int)a.size();
    while(l < r) {
        int mid = l + r >> 1;
        vector<int> paiu;
        for(int j = 0; j <= mid; ++j) paiu.push_back(a[j]);
        if(query(paiu, b)) {
            r = mid;
        } else l = mid + 1;
    }
    return a[r];
}

void run(int n) {
    dsu d(n + 5);
    for(int times = 0; times < n - 1; ++times) {
        int st = -1;
        vector<int> v;
        for(int i = 1; i <= n; ++i) v.push_back(d.get(i));
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        vector<int> A, B;
        vector<int> bits;
        vector<int> paiu;
        for(int bit = 0; (1 << bit) < (int)v.size(); ++bit) {
            vector<int> c1, c2;
            for(int i = 1; i <= n; ++i) {
                if((lower_bound(v.begin(), v.end(), d.get(i)) - v.begin()) & (1 << bit)) c1.push_back(i);
                else c2.push_back(i);
            }
            if(c1.empty() || c2.empty()) continue;
            if(query(c1, c2)) {
                A = c1, B = c2;
                break;
            }
        }
        assert(A.size() > 0 && B.size() > 0);
        vector<pair<int, int>> aa;
        for(auto x: A) aa.push_back({d.sz(x), x});
        sort(aa.rbegin(), aa.rend());
        A.clear();
        for(auto x: aa) A.push_back(x.second);
        aa.clear();
        for(auto x: B) aa.push_back({d.sz(x), x});
        sort(aa.rbegin(), aa.rend());
        B.clear();
        for(auto x: aa) B.push_back(x.second);

        int ansA = ask(A, B);
        int ansB = ask(B, A);
        d.uni(ansA, ansB);
        setRoad(ansA, ansB);
    }
}

/*
int main() {
    int n; cin >> n;
    run(n);
}
*/

Compilation message

icc.cpp: In function 'int ask(std::vector<int>, std::vector<int>)':
icc.cpp:40:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |         int mid = l + r >> 1;
      |                   ~~^~~
icc.cpp: In function 'void run(int)':
icc.cpp:53:13: warning: unused variable 'st' [-Wunused-variable]
   53 |         int st = -1;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Ok! 107 queries used.
2 Correct 5 ms 468 KB Ok! 110 queries used.
# Verdict Execution time Memory Grader output
1 Correct 28 ms 468 KB Ok! 562 queries used.
2 Correct 32 ms 500 KB Ok! 642 queries used.
3 Correct 34 ms 616 KB Ok! 655 queries used.
# Verdict Execution time Memory Grader output
1 Correct 116 ms 500 KB Ok! 1417 queries used.
2 Correct 106 ms 500 KB Ok! 1593 queries used.
3 Correct 106 ms 488 KB Ok! 1628 queries used.
4 Correct 101 ms 508 KB Ok! 1529 queries used.
# Verdict Execution time Memory Grader output
1 Correct 119 ms 468 KB Ok! 1534 queries used.
2 Correct 118 ms 488 KB Ok! 1577 queries used.
3 Correct 102 ms 468 KB Ok! 1604 queries used.
4 Correct 105 ms 488 KB Ok! 1548 queries used.
# Verdict Execution time Memory Grader output
1 Correct 104 ms 496 KB Ok! 1579 queries used.
2 Correct 131 ms 500 KB Ok! 1561 queries used.
3 Correct 112 ms 500 KB Ok! 1605 queries used.
4 Correct 104 ms 500 KB Ok! 1626 queries used.
5 Correct 101 ms 468 KB Ok! 1534 queries used.
6 Correct 109 ms 492 KB Ok! 1583 queries used.
# Verdict Execution time Memory Grader output
1 Correct 103 ms 504 KB Ok! 1605 queries used.
2 Correct 137 ms 504 KB Ok! 1590 queries used.