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>;
int st[200001], n, k = 1, cnt, cur = 1;
vector<int> X, Y, C;
void dfs(int u, int j )
{
if ( !st[- u - 1] )
{
if ( X[- u - 1] == 0 )
{
X[- u - 1] = j;
st[- u - 1] = 1;
} else {
st[- u - 1] = 1;
dfs(X[- u - 1], j);
}
} else {
if ( Y[- u - 1] == 0 )
{
Y[- u - 1] = j;
st[- u - 1] = 0;
} else {
st[- u - 1] = 0;
dfs(Y[- u - 1], j);
}
}
}
void create_circuit(int M, vector<int> A) {
n = A.size();
X.resize(n + log2(n));
Y.resize(n + log2(n));
while ( k < n )
k *= 2;
C.pub(A[0]);
for (int i = 1; i <= M; i++)
C.pub(-1);
queue<pair <int, pii> > q;
q.push(mp(n, mp(k / 2, -1)));
while (!q.empty())
{
int res = q.front().ff, num = q.front().ss.ff, at = q.front().ss.ss;
q.pop();
if ( num == 1 )
{
Y[-at - 1] = 0;
if ( res == 2 )
X[-at - 1] = 0;
else
X[-at - 1] = -1;
} else {
if ( res <= num )
X[-at - 1] = -1;
else
X[-at - 1] = -(++cur);
Y[-at - 1] = -(++cur);
if ( res > num )
{
q.push(mp(res - num, mp(num / 2, X[-at - 1])));
q.push(mp(num, mp(num / 2, Y[-at - 1])));
}
else
q.push(mp(res, mp(num / 2, Y[-at - 1])));
}
}
for (int i = 1; i < A.size(); i++)
dfs(-1, A[i]);
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:103:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for (int i = 1; i < A.size(); i++)
| ~~^~~~~~~~~~
# | 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... |