#include <bits/stdc++.h>
#include "doll.h"
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
using namespace std;
ll n, m, s, nxt[100005], k=0;
pll a[400005];
vector<ll> v[100005];
bool tt[400005];
ll build(int l,int r)
{
if (l==r)
{
return 0;
}
s--;
ll nw=s;
int w=(l+r)/2;
a[-nw].fi=build(l,w);
a[-nw].se=build(w+1,r);
return nw;
}
ll dfs(int nw,int l,int r,int k)
{
if (l==r)
{
return k;
}
int w=(l+r)/2;
if (!tt[nw])
{
ll o=dfs(a[-nw].fi, l, w, k);
if (o!=-1e18) a[-nw].fi=o;
}else
{
ll o=dfs(a[-nw].se, w+1, r, k);
if (o!=-1e18) a[-nw].se=o;
}
tt[nw]^=1;
return -1e18;
}
bool zz[1000005];
void create_circuit(int m, vector<int> aa) {
s=0;
for (int i = 1; i <= 1e6; i*=2) zz[i]=1;
aa.pb(0);
for (int i = 0; i < aa.size()-1; i++)
{
v[aa[i]].pb(aa[i+1]);
}
nxt[0]=aa[0];
for (int i = 1; i <= m; i++)
if (v[i].size()>0)
{
if (v[i].size()==1)
nxt[i]=v[i][0]; else
{
ll tt=0;
reverse(all(v[i]));
if (!zz[v[i].size()])
{
s--;
a[-s].fi=s;
a[-s].se=0;
tt=s;
}
while (!zz[v[i].size()])
{
v[i].pb(s);
}
reverse(all(v[i]));
ll o=build(0,v[i].size()-1);
nxt[i]=o;
if (tt!=0) a[-tt].se=o;
for (int j = 0; j < v[i].size(); j++)
dfs(o, 0, v[i].size()-1, v[i][j]);
}
}
std::vector<int> X, Y, C;
X.resize(-s);
Y.resize(-s);
C.resize(m+1);
for (int i = 0; i <= m; i++)
C[i]=(int)nxt[i];
for (int i = -1; i >= s; i--)
X[-i-1]=(int)a[-i].fi, Y[-i-1]=(int)a[-i].se;
/*cout << m << " " << aa.size() << "\n";
for (int i = 0; i < aa.size(); i++)cout << aa[i] << " ";
cout << "\n";
for (int i = 0; i < C.size(); i++)
cout << C[i] << " ";
cout << "\n";
for (int i = 0; i < X.size(); i++)
cout << X[i] << " ";
cout << "\n";
for (int i = 0; i < Y.size(); i++)
cout << Y[i] << " ";
cout << "\n";*/
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < aa.size()-1; i++)
| ~~^~~~~~~~~~~~~
doll.cpp:89:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int j = 0; j < v[i].size(); j++)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
36 ms |
7356 KB |
Output is correct |
3 |
Correct |
28 ms |
6828 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
13 ms |
3916 KB |
Output is correct |
6 |
Correct |
47 ms |
8912 KB |
Output is correct |
7 |
Correct |
2 ms |
2660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
36 ms |
7356 KB |
Output is correct |
3 |
Correct |
28 ms |
6828 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
13 ms |
3916 KB |
Output is correct |
6 |
Correct |
47 ms |
8912 KB |
Output is correct |
7 |
Correct |
2 ms |
2660 KB |
Output is correct |
8 |
Correct |
63 ms |
10552 KB |
Output is correct |
9 |
Correct |
65 ms |
10976 KB |
Output is correct |
10 |
Correct |
112 ms |
14672 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
4 ms |
2656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
36 ms |
7356 KB |
Output is correct |
3 |
Correct |
28 ms |
6828 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
13 ms |
3916 KB |
Output is correct |
6 |
Correct |
47 ms |
8912 KB |
Output is correct |
7 |
Correct |
2 ms |
2660 KB |
Output is correct |
8 |
Correct |
63 ms |
10552 KB |
Output is correct |
9 |
Correct |
65 ms |
10976 KB |
Output is correct |
10 |
Correct |
112 ms |
14672 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
4 ms |
2656 KB |
Output is correct |
14 |
Incorrect |
150 ms |
20176 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
2660 KB |
Output is partially correct |
2 |
Correct |
87 ms |
11580 KB |
Output is correct |
3 |
Partially correct |
206 ms |
19324 KB |
Output is partially correct |
4 |
Partially correct |
213 ms |
20040 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
2660 KB |
Output is partially correct |
2 |
Correct |
87 ms |
11580 KB |
Output is correct |
3 |
Partially correct |
206 ms |
19324 KB |
Output is partially correct |
4 |
Partially correct |
213 ms |
20040 KB |
Output is partially correct |
5 |
Partially correct |
138 ms |
22864 KB |
Output is partially correct |
6 |
Partially correct |
140 ms |
23956 KB |
Output is partially correct |
7 |
Partially correct |
162 ms |
23632 KB |
Output is partially correct |
8 |
Partially correct |
151 ms |
24524 KB |
Output is partially correct |
9 |
Partially correct |
176 ms |
17348 KB |
Output is partially correct |
10 |
Partially correct |
243 ms |
25524 KB |
Output is partially correct |
11 |
Partially correct |
156 ms |
25140 KB |
Output is partially correct |
12 |
Partially correct |
110 ms |
17472 KB |
Output is partially correct |
13 |
Partially correct |
94 ms |
16608 KB |
Output is partially correct |
14 |
Partially correct |
109 ms |
16296 KB |
Output is partially correct |
15 |
Partially correct |
93 ms |
15956 KB |
Output is partially correct |
16 |
Partially correct |
4 ms |
3020 KB |
Output is partially correct |
17 |
Partially correct |
95 ms |
14556 KB |
Output is partially correct |
18 |
Partially correct |
92 ms |
14528 KB |
Output is partially correct |
19 |
Partially correct |
99 ms |
15248 KB |
Output is partially correct |
20 |
Partially correct |
118 ms |
19156 KB |
Output is partially correct |
21 |
Partially correct |
182 ms |
22360 KB |
Output is partially correct |
22 |
Partially correct |
114 ms |
18272 KB |
Output is partially correct |