#pragma GCC optimize("O3")
//#pragma GCC tagret("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define ld long double
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type,
less<ll>, rb_tree_tag,
tree_order_statistics_node_update> oset;
mt19937 gen(time(0));
const int MOD = 1e9 + 7;
void answer(vector<int> C, vector<int> X, vector<int> Y);
bool used[400007];
vector<int> X, Y;
ll build(ll gl) {
if(gl == 0) {
X.pb(0);
Y.pb(0);
return X.size() - 1;
}
ll v1 = X.size();
X.pb(-1);
Y.pb(-1);
X[v1] = -build(gl - 1);
Y[v1] = -build(gl - 1);
return v1;
}
void go(ll v1, ll l, ll r, ll cr, ll root) {
v1 = -v1;
if(l + 1 == r) {
if(l < cr) {
X[v1] = root;
}
if(r < cr) {
Y[v1] = root;
}
return;
}
ll mid = (l + r) / 2;
go(X[v1], l, mid, cr, root);
go(Y[v1], mid + 1, r, cr, root);
}
set<ll> recalc(ll v1, ll gl) {
v1 = -v1;
set<ll> st1, st2;
if(gl == 0) {
st1.insert(X[v1]);
st2.insert(Y[v1]);
} else {
for(auto to: recalc(X[v1], gl - 1)) st1.insert(to);
for(auto to: recalc(Y[v1], gl - 1)) st2.insert(to);
}
if(st1.size() == 1) {
X[v1] = *st1.begin();
}
if(st2.size() == 1) {
Y[v1] = *st2.begin();
}
for(auto to: st2) st1.insert(to);
while(st1.size() > 2) st1.erase(*st1.rbegin());
return st1;
}
bool col(ll v1, ll x, ll gl) {
v1 = -v1;
if(gl == 0) {
used[v1] ^= 1;
if(used[v1]) {
if(X[v1] != 0) return 0;
X[v1] = x;
} else {
if(Y[v1] != 0) return 0;
Y[v1] = x;
}
return 1;
}
bool f = 0;
if(!used[v1]) f = col(X[v1], x, gl - 1);
else f = col(Y[v1], x, gl - 1);
used[v1] ^= 1;
return f;
}
void dob(ll v1, ll x, ll gl) {
while(true) {
if(col(v1, x, gl)) break;
}
}
void create_circuit(int M, vector<int> B) {
//if(A.size() != 16) exit(-1);
X.clear();
Y.clear();
vector<ll> A;
for(int i = 1; i < B.size(); i++) {
A.pb(B[i]);
}
A.pb(0);
vector<int> sl(M + 1, 0);
X.pb(0);
Y.pb(0);
ll now = 0;
while((2 << now) < A.size()) {
now++;
}
ll root = -build(now);
for(auto &to: sl) to = root;
ll d = (2 << now) - A.size();
go(root, 0, (2 << now) - 1, d, root);
for(auto to: A) {
dob(root, to, now);
}
recalc(root, now);
sl[0] = B[0];
set<ll> all;
for(auto to: sl) {
if(to < 0) all.insert(-to);
}
for(int i = 1; i < X.size(); i++) {
if(X[i] < 0) all.insert(-X[i]);
if(Y[i] < 0) all.insert(-Y[i]);
}
map<ll,ll> mp;
ll e = -1;
for(auto to: all) {
mp[to] = e;
e--;
}
vector<int> x, y;
for(int i = 1; i < X.size(); i++) {
if(!all.count(i)) continue;
if(X[i] >= 0) x.pb(X[i]);
else
x.pb(mp[-X[i]]);
if(Y[i] >= 0) y.pb(Y[i]);
else
y.pb(mp[-Y[i]]);
}
for(auto &to: sl) {
if(to < 0) to = mp[-to];
}
answer(sl, x, y);
}
#ifdef LOCAL
int32_t main() {
}
#endif
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for(int i = 1; i < B.size(); i++) {
| ~~^~~~~~~~~~
doll.cpp:126:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
126 | while((2 << now) < A.size()) {
| ~~~~~~~~~~~^~~~~~~~~~
doll.cpp:145:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
145 | for(int i = 1; i < X.size(); i++) {
| ~~^~~~~~~~~~
doll.cpp:157:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
157 | for(int i = 1; i < X.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
94 ms |
12312 KB |
Output is correct |
3 |
Correct |
114 ms |
13024 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
13 ms |
1492 KB |
Output is correct |
6 |
Correct |
148 ms |
19148 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
94 ms |
12312 KB |
Output is correct |
3 |
Correct |
114 ms |
13024 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
13 ms |
1492 KB |
Output is correct |
6 |
Correct |
148 ms |
19148 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
178 ms |
22160 KB |
Output is correct |
9 |
Correct |
243 ms |
24100 KB |
Output is correct |
10 |
Correct |
298 ms |
34260 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
94 ms |
12312 KB |
Output is correct |
3 |
Correct |
114 ms |
13024 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
13 ms |
1492 KB |
Output is correct |
6 |
Correct |
148 ms |
19148 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
178 ms |
22160 KB |
Output is correct |
9 |
Correct |
243 ms |
24100 KB |
Output is correct |
10 |
Correct |
298 ms |
34260 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
294 ms |
33720 KB |
Output is correct |
15 |
Correct |
229 ms |
22820 KB |
Output is correct |
16 |
Correct |
289 ms |
33600 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
232 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
288 ms |
34128 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
53 ms |
4772 KB |
Output is correct |
3 |
Correct |
133 ms |
6944 KB |
Output is correct |
4 |
Correct |
124 ms |
8480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
53 ms |
4772 KB |
Output is correct |
3 |
Correct |
133 ms |
6944 KB |
Output is correct |
4 |
Correct |
124 ms |
8480 KB |
Output is correct |
5 |
Correct |
290 ms |
33580 KB |
Output is correct |
6 |
Correct |
305 ms |
33248 KB |
Output is correct |
7 |
Correct |
287 ms |
33344 KB |
Output is correct |
8 |
Correct |
298 ms |
33160 KB |
Output is correct |
9 |
Correct |
184 ms |
17596 KB |
Output is correct |
10 |
Correct |
283 ms |
29968 KB |
Output is correct |
11 |
Correct |
285 ms |
32956 KB |
Output is correct |
12 |
Correct |
215 ms |
22332 KB |
Output is correct |
13 |
Correct |
167 ms |
21456 KB |
Output is correct |
14 |
Correct |
230 ms |
22620 KB |
Output is correct |
15 |
Correct |
213 ms |
22684 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
175 ms |
21404 KB |
Output is correct |
18 |
Correct |
165 ms |
21264 KB |
Output is correct |
19 |
Correct |
211 ms |
22480 KB |
Output is correct |
20 |
Correct |
305 ms |
32988 KB |
Output is correct |
21 |
Correct |
285 ms |
32956 KB |
Output is correct |
22 |
Correct |
310 ms |
32828 KB |
Output is correct |