This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
bool bo[200001];
int st[200001];
void create_circuit(int M, vector<int> A) {
A.pub(0);
int N = A.size();
vector<int> C(M + 1);
set<int> ext;
for (int i = 1; i <= M; i++)
C[i] = -1;
C[0] = A[0];
ext.insert(1);
vector<int> X, Y;
while (ext.size() * 2 < A.size() - 1 || pow(2, (int)log2(ext.size())) != ext.size() )
{
auto it = ext.begin();
while ( X.size() < *it )
X.pub(1e9), Y.pub(1e9);
X[*it - 1] = -(*it * 2);
Y[*it - 1] = -(*it * 2 + 1);
ext.insert(*it * 2);
ext.insert(*it * 2 + 1);
while ( *it * 2 + 1 > X.size() )
{
X.pub(1e9);
Y.pub(1e9);
}
ext.erase(it);
}
int num = 0, u = 0, z = 1, p = 2 * ext.size() - (A.size() - 1);
while ( num < ext.size() * 2 )
{
// cout << u << "\n";
if ( (X[u] == 1e9 && !st[u]) || (Y[u] == 1e9 && st[u]) )
{
if ( z < A.size() && !p )
{
if ( !st[u] )
{
X[u] = A[z++];
st[u] = 1;
} else
{
Y[u] = A[z++];
st[u] = 0;
}
} else {
if ( !st[u] )
{
X[u] = -1;
st[u] = 1;
} else
{
Y[u] = -1;
st[u] = 0;
}
p--;
}
u = 0;
num++;
} else {
if ( st[u] )
{
st[u] ^= 1;
u = -Y[u] - 1;
} else
st[u] ^= 1, u = -X[u] - 1;
}
}
// for (auto x : C)
// cout << x << " ";
//
// cout << "\n";
//
// for (auto x : X)
// cout << x << " ";
//
// cout << "\n";
//
// for (auto x : Y)
// cout << x << " ";
//
// cout << "\n";
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:43:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
43 | while ( X.size() < *it )
| ~~~~~~~~~^~~~~
doll.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | while ( *it * 2 + 1 > X.size() )
| ~~~~~~~~~~~~^~~~~~~~~~
doll.cpp:60:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | while ( num < ext.size() * 2 )
| ~~~~^~~~~~~~~~~~~~~~
doll.cpp:65:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | if ( z < A.size() && !p )
| ~~^~~~~~~~~~
doll.cpp:30:6: warning: unused variable 'N' [-Wunused-variable]
30 | int N = A.size();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |