#include "doll.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n;
const int INF=1e9;
vector<int> vecini[100005];
vector<int> C,X,Y;
vector<int> v;
int lft[5000005],rgt[5000005];
int s;
int state[5000005];
int added=0;
int build(int st,int dr)
{
if(st==dr)
return INF;
ll lg=dr-st+1;
if(__builtin_popcount(lg)==1)
{
ll mij=(st+dr)/2;
ll a=build(st,mij);
ll b=build(mij+1,dr);
s++;
lft[s]=a;
rgt[s]=b;
return -s;
}
ll lsb=(lg&(-lg));
ll poz=dr-lsb;
ll a=build(st,poz);
ll b=build(poz+1,dr);
s++;
lft[s]=a;
rgt[s]=b;
return -s;
}
int plsmake()
{
if(v.size()==1)
return v[0];
ll lg=v.size();
int c=build(0,lg-1);
vector<pii> ord;
for(int i=1;i<=lg;i++)
{
int nod=c;
while(true)
{
nod=abs(nod);
if(state[nod]==0)
{
if(lft[nod]==INF)
{
ord.push_back({nod,0});
state[nod]^=1;
break;
}
state[nod]=1;
nod=lft[nod];
continue;
}
else
{
if(rgt[nod]==INF)
{
ord.push_back({nod,1});
state[nod]^=1;
break;
}
state[nod]=0;
nod=rgt[nod];
continue;
}
}
}
for(int i=0;i<ord.size();i++)
{
int who=ord[i].first;
int dir=ord[i].second;
if(i+1<v.size())
{
if(dir==0)
lft[who]=v[i];
else
rgt[who]=v[i];
continue;
}
if(i+1==ord.size())
{
if(dir==0)
lft[who]=v.back();
else
rgt[who]=v.back();
continue;
}
if(dir==0)
lft[who]=c;
else
rgt[who]=c;
}
return c;
}
void create_circuit(int M, std::vector<int> A)
{
C.resize(M+1);
n=A.size();
if(n==16)
{
C[0]=A[0];
for(int i=1;i<A.size();i++)
v.push_back(A[i]);
v.push_back(0);
int c=plsmake();
for(int i=1;i<=M;i++)
C[i]=c;
for(int i=1;i<=s;i++)
{
X.push_back(lft[i]);
Y.push_back(rgt[i]);
}
answer(C,X,Y);
return;
}
for(int i=0;i<A.size();i++)
{
int x=A[i];
int nxt=0;
if(i+1<A.size())
nxt=A[i+1];
vecini[x].push_back(nxt);
}
C[0]=A[0];
for(int i=1;i<=M;i++)
{
if(vecini[i].empty())
{
C[i]=0;
continue;
}
else
{
v=vecini[i];
C[i]=plsmake();
}
}
for(int i=1;i<=s;i++)
{
X.push_back(lft[i]);
Y.push_back(rgt[i]);
}
/*for(int i=0;i<C.size();i++)
cout<<C[i]<<' ';
cout<<'\n';
for(int i=1;i<=s;i++)
cout<<-i<<' '<<X[i-1]<<' '<<Y[i-1]<<'\n';*/
answer(C,X,Y);
}
Compilation message
doll.cpp: In function 'int plsmake()':
doll.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i=0;i<ord.size();i++)
| ~^~~~~~~~~~~
doll.cpp:83:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | if(i+1<v.size())
| ~~~^~~~~~~~~
doll.cpp:91:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | if(i+1==ord.size())
| ~~~^~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:113:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int i=1;i<A.size();i++)
| ~^~~~~~~~~
doll.cpp:127:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | for(int i=0;i<A.size();i++)
| ~^~~~~~~~~
doll.cpp:131:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | if(i+1<A.size())
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3672 KB |
Output is correct |
2 |
Correct |
18 ms |
7912 KB |
Output is correct |
3 |
Correct |
15 ms |
7576 KB |
Output is correct |
4 |
Correct |
1 ms |
5760 KB |
Output is correct |
5 |
Correct |
9 ms |
7124 KB |
Output is correct |
6 |
Correct |
22 ms |
9496 KB |
Output is correct |
7 |
Correct |
1 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3672 KB |
Output is correct |
2 |
Correct |
18 ms |
7912 KB |
Output is correct |
3 |
Correct |
15 ms |
7576 KB |
Output is correct |
4 |
Correct |
1 ms |
5760 KB |
Output is correct |
5 |
Correct |
9 ms |
7124 KB |
Output is correct |
6 |
Correct |
22 ms |
9496 KB |
Output is correct |
7 |
Correct |
1 ms |
3676 KB |
Output is correct |
8 |
Correct |
37 ms |
14792 KB |
Output is correct |
9 |
Correct |
38 ms |
15256 KB |
Output is correct |
10 |
Correct |
55 ms |
18640 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3672 KB |
Output is correct |
2 |
Correct |
18 ms |
7912 KB |
Output is correct |
3 |
Correct |
15 ms |
7576 KB |
Output is correct |
4 |
Correct |
1 ms |
5760 KB |
Output is correct |
5 |
Correct |
9 ms |
7124 KB |
Output is correct |
6 |
Correct |
22 ms |
9496 KB |
Output is correct |
7 |
Correct |
1 ms |
3676 KB |
Output is correct |
8 |
Correct |
37 ms |
14792 KB |
Output is correct |
9 |
Correct |
38 ms |
15256 KB |
Output is correct |
10 |
Correct |
55 ms |
18640 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Incorrect |
62 ms |
18368 KB |
state 'Y' |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
2 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5808 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5724 KB |
wrong serial number |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
5724 KB |
wrong serial number |
2 |
Halted |
0 ms |
0 KB |
- |