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 <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i)
#define RFOR(i, x, n) for (ll i =x; i>=n; --i)
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;
vector<ll> a;
unordered_map<ll, vector<ll> > pos;
vector<int> X, C, Y;
ll cnt = -1, fir = -1;
bool compare(pii a, pii b) {return a.s < b.s; }
void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);
vector<pii> dfs(ll layer, ll tot)
{
vector<pii> ret;
ll now = ++cnt;
if (layer==1)
{
ret.pb(mp(mp(now, 0), 2));
if (tot==1) {X[now] = -fir-1; return ret;}
ret.pb(mp(mp(now, 1), 1));
return ret;
}
Y[now] = -cnt-2;
vector<pii> ri = dfs(layer-1, tot);
vector<pii> le;
if (tot - (1LL << (layer-1)) > 0){ X[now] = -cnt-2; le = dfs(layer-1,tot - (1LL << (layer-1)));}
else {X[now] = -fir-1;}
for (ll i=0; i<le.size(); ++i) le[i].s = le[i].s*2 - 1;
for (ll i=0; i<ri.size(); ++i) ri[i].s = ri[i].s*2;
ret.resize(le.size() + ri.size());
merge(all(le), all(ri), ret.begin());
return ret;
}
void create_circuit(int M, std::vector<int> A)
{
ll n = A.size();
C.resize(M+1, 0);
X.resize(2*n, 0); Y.resize(2*n, 0);
ll k = 64 - __builtin_clzll(n);
fir = cnt+1;
for (ll i=0; i<=M; ++i) C[i] = -fir-1;
vector<pii> order = dfs(k, n+1);
sort(all(order), compare);
A.pb(0);
for (ll i=0; i<n+1; ++i)
{
ll key = order[i].f.f, side = order[i].f.s;
if (side) X[key] = A[i];
else Y[key] = A[i];
}
X.resize(cnt+1); Y.resize(cnt+1);
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> > dfs(ll, ll)':
doll.cpp:64:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (ll i=0; i<le.size(); ++i) le[i].s = le[i].s*2 - 1;
| ~^~~~~~~~~~
doll.cpp:65:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (ll i=0; i<ri.size(); ++i) ri[i].s = ri[i].s*2;
| ~^~~~~~~~~~
# | 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... |