Submission #707236

# Submission time Handle Problem Language Result Execution time Memory
707236 2023-03-08T15:49:01 Z Tuanlinh123 ICC (CEOI16_icc) C++17
100 / 100
130 ms 588 KB
#include<bits/stdc++.h>
#include "icc.h"
#define ll int
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
 
using namespace std;
 
ll a[105], pa[105], Rank[105];
 
ll Find(ll i)
{
    if (pa[i]!=i)
        pa[i]=Find(pa[i]);
    return pa[i];
}
 
void Union(ll a, ll b)
{
    ll Pa=Find(a), Pb=Find(b);
    if (Pa==Pb) return;
    if (Rank[Pa]<Rank[Pb]) swap(Pa, Pb);
    if (Rank[Pa]==Rank[Pb]) Rank[Pa]++;
    pa[Pb]=Pa;
}
 
ll ask(vector <ll> a, vector <ll> b)
{
    ll n=a.size(), m=b.size();
    ll A[n], B[m];
    for (ll i=0; i<a.size(); i++)
        A[i]=a[i];
    for (ll i=0; i<b.size(); i++)
        B[i]=b[i];
    return query(n, m, A, B);
}
 
ll random(ll l, ll r)
{
    return l+rand()%(r-l+1);
}
 
void run(ll n)
{
    srand(070405);
    for (ll i=1; i<=n; i++)
        pa[i]=i, a[i-1]=i;
    ll lg=32-__builtin_clz(n);
    for (ll k=1; k<n; k++)
    {
        for (ll i=0; i<lg; i++)
        {
            vector <ll> A, B;
            for (ll j=0; j<n; j++)
            {
                ll Pj=Find(a[j]);
                if (Pj&1<<i)
                    A.pb(a[j]);
                else B.pb(a[j]);
            }
            if (!ask(A, B))
                continue;
            for (ll i=0; i<A.size()+B.size(); i++)
            {
                ll lA=random(0, A.size()-1), rA=random(0, A.size()-1);
                ll lB=random(0, B.size()-1), rB=random(0, B.size()-1);
                swap(A[lA], A[rA]);
                swap(B[lB], B[rB]);
            }
            ll loA=0, hiA=A.size()-1;
            while (hiA>loA)
            {
                ll midA=(hiA+loA)/2;
                vector <ll> Anew(A.begin()+loA, A.begin()+midA+1);
                if (ask(Anew, B))
                    hiA=midA;
                else loA=midA+1;
            }
            ll loB=0, hiB=B.size()-1;
            while (hiB>loB)
            {
                ll midB=(hiB+loB)/2;
                vector <ll> Bnew(B.begin()+loB, B.begin()+midB+1);
                if (ask(A, Bnew))
                    hiB=midB;
                else loB=midB+1;
            }
            setRoad(A[loA], B[loB]);
            Union(A[loA], B[loB]);
            break;
        }
    }
}

Compilation message

icc.cpp: In function 'int ask(std::vector<int>, std::vector<int>)':
icc.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (ll i=0; i<a.size(); i++)
      |                  ~^~~~~~~~~
icc.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (ll i=0; i<b.size(); i++)
      |                  ~^~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for (ll i=0; i<A.size()+B.size(); i++)
      |                          ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 468 KB Ok! 105 queries used.
2 Correct 5 ms 468 KB Ok! 102 queries used.
# Verdict Execution time Memory Grader output
1 Correct 30 ms 480 KB Ok! 539 queries used.
2 Correct 40 ms 480 KB Ok! 670 queries used.
3 Correct 38 ms 476 KB Ok! 664 queries used.
# Verdict Execution time Memory Grader output
1 Correct 96 ms 588 KB Ok! 1356 queries used.
2 Correct 116 ms 480 KB Ok! 1637 queries used.
3 Correct 93 ms 488 KB Ok! 1362 queries used.
4 Correct 108 ms 480 KB Ok! 1506 queries used.
# Verdict Execution time Memory Grader output
1 Correct 101 ms 500 KB Ok! 1443 queries used.
2 Correct 99 ms 484 KB Ok! 1431 queries used.
3 Correct 115 ms 492 KB Ok! 1612 queries used.
4 Correct 89 ms 500 KB Ok! 1314 queries used.
# Verdict Execution time Memory Grader output
1 Correct 112 ms 484 KB Ok! 1598 queries used.
2 Correct 130 ms 480 KB Ok! 1608 queries used.
3 Correct 110 ms 480 KB Ok! 1625 queries used.
4 Correct 106 ms 492 KB Ok! 1553 queries used.
5 Correct 95 ms 480 KB Ok! 1401 queries used.
6 Correct 111 ms 588 KB Ok! 1552 queries used.
# Verdict Execution time Memory Grader output
1 Correct 113 ms 468 KB Ok! 1612 queries used.
2 Correct 118 ms 484 KB Ok! 1624 queries used.