#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
typedef pair<int,int> ii;
set<int> sss;
void create_circuit(int M, std::vector<int> A) {
int n = A.size();
vector<int> C(M + 1);
//C[0] = 1;
//C[1] = -1;
//C[2] = 1;
//C[3] = 0;
//C[4] = 0;
int sw = 1000000;
int xxx = 1;
while(xxx < 1000000){
sss.insert(xxx);
xxx *= 2;
}
vector<int> X, Y;
// X.push_back(2);
//Y.push_back(3);
vector<int> target[M+1];
for(int i = 0;i < n-1;i++){
target[A[i]].push_back(A[i+1]);
}
target[A[n-1]].push_back(0);
target[0].push_back(A[0]);
map<int, ii> mm;
vector<int> t;
/*
for(int i = 0;i <= M;i++){
//printf("%d: ",i);
if(target[i].size() == 0) C[i] = 0;
else if(target[i].size() == 1) C[i] = target[i][0];
else{
t.push_back()
int nn = *sss.lower_bound(target[i].size());
int tree[2 * nn];
tree[0] = 0;
for(int j = nn;j < 2 * nn;j++){
int l = j;
int v = 0;
while(l > 1){
v *= 2;
if(l % 2 == 1) v++;
l /= 2;
}
tree[j] = v;
}
for(int j = 1;j < nn;j++){
tree[j] = sw;
sw++;
}
map<int,int> dis;
for(int j = nn;j < 2 * nn;j++){
if(j - nn < nn-target[i].size()) tree[j] = tree[1];
else dis[tree[j]] = j;
//else tree[j] = target[i][tree[j] - (nn - target[i].size())];
}
int c = 0;
for(map<int,int>::iterator it = dis.begin();it != dis.end();it++){
tree[it->second] = target[i][c];
c++;
}
//for(int j = 0;j < 2 * nn;j++){
// printf("%d ",tree[j]);
//}
for(int j = nn-1;j >= 1;j--){
if(tree[j*2] == tree[j*2+1]){
tree[j] = tree[j*2];
tree[j*2] = -1234567;
tree[j*2+1] = -1234567;
}
}
for(int j = 1;j < nn;j++){
if(tree[j*2] == -1234567) continue;
mm[tree[j]] = ii(tree[j*2],tree[j*2+1]);
}
C[i] = tree[1];
C[i] = 10000000;
}
//printf("\n");
}
*/
for(int i = 0;i <= M;i++){
if(target[i].size() == 0) C[i] = 0;
else if(target[i].size() == 1) C[i] = target[i][0];
else{
C[i] = sw;
}
}
for(int i = 0;i < n;i++){
if(C[A[i]] == sw){
if(i == n-1) t.push_back(0);
else t.push_back(A[i+1]);
}
}
/*
for(int i = 0;i < t.size();i++){
printf("%d ",t[i]);
}
printf("\n\n\n");
*/
int nn = *sss.lower_bound(t.size());
int tree[2 * nn];
tree[0] = 0;
for(int j = nn;j < 2 * nn;j++){
int l = j;
int v = 0;
while(l > 1){
v *= 2;
if(l % 2 == 1) v++;
l /= 2;
}
tree[j] = v;
}
for(int j = 1;j < nn;j++){
tree[j] = sw;
sw++;
}
map<int,int> dis;
for(int j = nn;j < 2 * nn;j++){
if(j - nn < nn-t.size()) tree[j] = tree[1];
else dis[tree[j]] = j;
//else tree[j] = t[tree[j] - (nn - t.size())];
}
int c = 0;
for(map<int,int>::iterator it = dis.begin();it != dis.end();it++){
tree[it->second] = t[c];
c++;
}
//for(int j = 0;j < 2 * nn;j++){
// printf("%d ",tree[j]);
//}
for(int j = nn-1;j >= 1;j--){
if(tree[j*2] == tree[j*2+1]){
tree[j] = tree[j*2];
tree[j*2] = -1234567;
tree[j*2+1] = -1234567;
}
}
for(int j = 1;j < nn;j++){
if(tree[j*2] == -1234567) continue;
mm[tree[j]] = ii(tree[j*2],tree[j*2+1]);
}
///
///
///
//map<int,int> dis;
dis.clear();
for(map<int,ii>::iterator it = mm.begin();it != mm.end();it++){
if(it->first >= 1000000) dis[it->first] = 0;
if(it->second.first >= 1000000) dis[it->second.first] = 0;
if(it->second.second >= 1000000) dis[it->second.second] = 0;
}
c = -1;
for(map<int,int>::iterator it = dis.begin();it != dis.end();it++){
it->second = c;
c--;
}
for(map<int,ii>::iterator it = mm.begin();it != mm.end();it++){
if(it->first < 1000000) dis[it->first] = it->first;
if(it->second.first < 1000000) dis[it->second.first] = it->second.first;
if(it->second.second < 1000000) dis[it->second.second] = it->second.second;
}
map<int,ii> mmm;
for(map<int,ii>::iterator it = mm.begin();it != mm.end();it++){
mmm[dis[it->first]] = ii(dis[it->second.first],dis[it->second.second]);
}
for(map<int,ii>::iterator it = mmm.begin();it != mmm.end();it++){
X.push_back(it->second.first);
Y.push_back(it->second.second);
}
reverse(X.begin(),X.end());
reverse(Y.begin(),Y.end());
for(int i = 0;i < C.size();i++){
if(C[i] >= 1000000) C[i] = dis[C[i]];
//printf("%d ",C[i]);
}
//printf("\n");
for(int i = 0;i < X.size();i++){
//printf("%d %d\n",X[i],Y[i]);
}
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:132:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
132 | if(j - nn < nn-t.size()) tree[j] = tree[1];
| ~~~~~~~^~~~~~~~~~~~~
doll.cpp:188:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
188 | for(int i = 0;i < C.size();i++){
| ~~^~~~~~~~~~
doll.cpp:194:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
194 | for(int i = 0;i < X.size();i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
33 ms |
6388 KB |
Output is correct |
3 |
Correct |
29 ms |
5104 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
7612 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
33 ms |
6388 KB |
Output is correct |
3 |
Correct |
29 ms |
5104 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
7612 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
494 ms |
35916 KB |
Output is correct |
9 |
Correct |
273 ms |
28992 KB |
Output is correct |
10 |
Correct |
837 ms |
55092 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
33 ms |
6388 KB |
Output is correct |
3 |
Correct |
29 ms |
5104 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
7612 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
494 ms |
35916 KB |
Output is correct |
9 |
Correct |
273 ms |
28992 KB |
Output is correct |
10 |
Correct |
837 ms |
55092 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
700 ms |
51364 KB |
Output is correct |
15 |
Correct |
437 ms |
33400 KB |
Output is correct |
16 |
Correct |
739 ms |
49516 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
654 ms |
50588 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
102 ms |
9536 KB |
Output is correct |
3 |
Correct |
88 ms |
10516 KB |
Output is correct |
4 |
Correct |
169 ms |
14852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
102 ms |
9536 KB |
Output is correct |
3 |
Correct |
88 ms |
10516 KB |
Output is correct |
4 |
Correct |
169 ms |
14852 KB |
Output is correct |
5 |
Correct |
742 ms |
49240 KB |
Output is correct |
6 |
Correct |
676 ms |
47456 KB |
Output is correct |
7 |
Correct |
728 ms |
47964 KB |
Output is correct |
8 |
Correct |
688 ms |
46564 KB |
Output is correct |
9 |
Correct |
312 ms |
24968 KB |
Output is correct |
10 |
Correct |
653 ms |
41980 KB |
Output is correct |
11 |
Correct |
626 ms |
45500 KB |
Output is correct |
12 |
Correct |
351 ms |
31316 KB |
Output is correct |
13 |
Correct |
367 ms |
31128 KB |
Output is correct |
14 |
Correct |
384 ms |
32372 KB |
Output is correct |
15 |
Correct |
396 ms |
33120 KB |
Output is correct |
16 |
Correct |
9 ms |
1228 KB |
Output is correct |
17 |
Correct |
333 ms |
29632 KB |
Output is correct |
18 |
Correct |
396 ms |
29580 KB |
Output is correct |
19 |
Correct |
387 ms |
31104 KB |
Output is correct |
20 |
Correct |
576 ms |
45412 KB |
Output is correct |
21 |
Correct |
622 ms |
45220 KB |
Output is correct |
22 |
Correct |
644 ms |
45000 KB |
Output is correct |