# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112911 | imaxblue | Mechanical Doll (IOI18_doll) | C++17 | 0 ms | 0 KiB |
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>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2
#define rseg (L+R)/2+1, R, N*2+1
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
/*
void answer(vector<int> C, vector<int> X, vector<int> Y){
fox(l, C.size()) cout << C[l] << ' '; cout << endl;
fox(l, X.size()){
cout << X[l] << ' ' << Y[l] << endl;
}
}*/
int n, n2, m, cnt, x[800005], y[800005], a2[300000];
vector<int> a;
map<int, int> com;
vector<int> c, x2, y2;
vector<pii> v;
int solve(int L, int R, int N){
if (L == R){
return a2[L];
}
x[N] = solve(lseg);
y[N] = solve(rseg);
//cout << N << ' ' << L << ' ' << R << ' ' << x[N] << ' ' << y[N] << endl;
if (x[N] == -1 && y[N] == -1){
x[N] = y[N] = 0x3f3f3f3f;
return -1;
}
return -N;
}
int rev(int x){
int res = 0;
for (int l = 0; l < 22; ++l, x/=2){res = res*2+x%2;}
return res;
}
void create_circuit(int M, vector<int> A){
m = M;
fox(l, m+1){
c.pb(-1);
}
flood(x);
flood(y);
a = A;
a.pb(0);
n2 = n = a.size();
for (; (n&-n) != n; ++n){
a2[n - n2] = -1;
}
for(int l = n - n2; l < n; ++l){
v.pb(mp(rev(l), l));
}
sort(v.begin(), v.end());
fox(l, n2){
a2[v[l].y] = a[l];
}
fox(l, n){
//cout << a2[l] << ' ';
}
//cout << endl;
//return;
solve(0, n-1, 1);
fox1(l, 2*n){
//cout << l << ' ' << x[l] << ' ' << y[l] << endl;
if (x[l] != 0x3f3f3f3f){
com[-l] = --cnt;
//cout << "*" << l << ' ' << cnt << endl;
}
}
fox1(l, 2*n){
if (x[l] != 0x3f3f3f3f){
if (x[l] >= 0) x2.pb(x[l]);
else x2.pb(com[x[l]]);
if (y[l] >= 0) y2.pb(y[l]);
else y2.pb(com[y[l]]);
}
}
answer(c, x2, y2);
}
/*
int main(){
int n, m, a;
vector<int> A;
cin >> m >> n;
fox(l, n){
cin >> a;
A.pb(a);
}
create_circuit(m, A);
return 0;
}*/
/*
4 4
1 2 1 3
*/