#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) x.begin(),x.end()
typedef long long ll;
#define INF 99999999999999
#define pb push_back
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
A.pb(0);
vector<int> C(M + 1);
vector<vector<int>>vis(M+1);
vector<int>sw(M+1,0);
ll idx=0;
vector<int> X, Y;
C[0]=A[0];
for(int i=0;i<N;i++)
vis[A[i]].pb(i);
for(int i=1;i<=M;i++)
{
if(!vis[i].size())
continue;
if(vis[i].size()==1)
{
C[i]=A[vis[i][0]+1];
continue;
}
ll j=0;
while((1<<j)<vis[i].size())
j++;
ll start=idx;
C[i]=-(idx+1);
X.pb(-(idx+1));
Y.pb(-(idx+1));
queue<pair<pair<int,int>,pair<int,int>>>q;
q.push({{1,idx},{0,1}});
idx++;
while(!q.empty())
{
ll d=q.front().F.F,id=q.front().F.S;
ll l=q.front().S.F,r=q.front().S.S;
q.pop();
if(j==d)
{
if(l<vis[i].size()-1);
X[id]=A[vis[i][l]+1];
if(r<vis[i].size()-1)
Y[id]=A[vis[i][r]+1];
if(r==(1<<j)-1)
Y[id]=A[vis[i][vis[i].size()-1]+1];
continue;
}
if(l<vis[i].size()-1)
{
X[id]=-(idx+1);
X.pb(-(start+1));
Y.pb(-(start+1));
q.push({{d+1,idx},{l,l+(1<<d)}});
}
if(r==(1<<d)-1 || r<vis[i].size())
{
idx++;
Y[id]=-(idx+1);
X.pb(-(start+1));
Y.pb(-(start+1));
q.push({{d+1,idx},{r,r+(1<<d)}});
idx++;
}
}
}
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | while((1<<j)<vis[i].size())
| ~~~~~~^~~~~~~~~~~~~~
doll.cpp:55:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | if(l<vis[i].size()-1);
| ~^~~~~~~~~~~~~~~~
doll.cpp:55:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
55 | if(l<vis[i].size()-1);
| ^~
doll.cpp:56:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
56 | X[id]=A[vis[i][l]+1];
| ^
doll.cpp:57:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if(r<vis[i].size()-1)
| ~^~~~~~~~~~~~~~~~
doll.cpp:64:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | if(l<vis[i].size()-1)
| ~^~~~~~~~~~~~~~~~
doll.cpp:72:32: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | if(r==(1<<d)-1 || r<vis[i].size())
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
31 ms |
7160 KB |
Output is correct |
3 |
Correct |
16 ms |
5868 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
4180 KB |
Output is correct |
6 |
Correct |
30 ms |
8804 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
31 ms |
7160 KB |
Output is correct |
3 |
Correct |
16 ms |
5868 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
4180 KB |
Output is correct |
6 |
Correct |
30 ms |
8804 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
39 ms |
8512 KB |
Output is correct |
9 |
Correct |
41 ms |
9924 KB |
Output is correct |
10 |
Correct |
82 ms |
13068 KB |
Output is correct |
11 |
Correct |
2 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
31 ms |
7160 KB |
Output is correct |
3 |
Correct |
16 ms |
5868 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
4180 KB |
Output is correct |
6 |
Correct |
30 ms |
8804 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
39 ms |
8512 KB |
Output is correct |
9 |
Correct |
41 ms |
9924 KB |
Output is correct |
10 |
Correct |
82 ms |
13068 KB |
Output is correct |
11 |
Correct |
2 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
67 ms |
12620 KB |
Output is correct |
15 |
Correct |
36 ms |
7116 KB |
Output is correct |
16 |
Correct |
68 ms |
10268 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
61 ms |
12440 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Correct |
30 ms |
7108 KB |
Output is correct |
3 |
Partially correct |
61 ms |
10024 KB |
Output is partially correct |
4 |
Partially correct |
70 ms |
11428 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Correct |
30 ms |
7108 KB |
Output is correct |
3 |
Partially correct |
61 ms |
10024 KB |
Output is partially correct |
4 |
Partially correct |
70 ms |
11428 KB |
Output is partially correct |
5 |
Partially correct |
76 ms |
13720 KB |
Output is partially correct |
6 |
Partially correct |
96 ms |
14208 KB |
Output is partially correct |
7 |
Partially correct |
88 ms |
14004 KB |
Output is partially correct |
8 |
Partially correct |
103 ms |
14376 KB |
Output is partially correct |
9 |
Partially correct |
51 ms |
10120 KB |
Output is partially correct |
10 |
Partially correct |
80 ms |
15384 KB |
Output is partially correct |
11 |
Partially correct |
78 ms |
14576 KB |
Output is partially correct |
12 |
Partially correct |
50 ms |
10176 KB |
Output is partially correct |
13 |
Partially correct |
60 ms |
9292 KB |
Output is partially correct |
14 |
Partially correct |
52 ms |
9164 KB |
Output is partially correct |
15 |
Partially correct |
72 ms |
9032 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
564 KB |
Output is partially correct |
17 |
Partially correct |
41 ms |
8100 KB |
Output is partially correct |
18 |
Partially correct |
51 ms |
8060 KB |
Output is partially correct |
19 |
Partially correct |
44 ms |
9252 KB |
Output is partially correct |
20 |
Partially correct |
91 ms |
11320 KB |
Output is partially correct |
21 |
Partially correct |
69 ms |
13208 KB |
Output is partially correct |
22 |
Partially correct |
56 ms |
10820 KB |
Output is partially correct |