This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
//salida rapida "\n"
//DECIMALES fixed<<sp(n)<<x<<endl;
//gcd(a,b)= ax + by
//lCB x&-x
//set.erase(it) - ersases the element present at the required index//auto it = s.find(element)
//set.find(element) - iterator pointing to the given element if it is present else return pointer pointing to set.end()
//set.lower_bound(element) - iterator pointing to element greater than or equal to the given element
//set.upper_bound(element) - iterator pointing to element greater than the given element
// | ^
//__builtin_popcount(x)
using namespace std;
void create_circuit(int m,vi A) {
int n = A.size();
vi C(m + 1,-1);
vi vis(m+1,0);
C[0]=A[0];
int num=0;
for(int i=0;i<n;i++)vis[A[i]]++;
for(int i=1;i<=m;i++){
if(vis[i]==0)C[i]=0;
if(vis[i]==2)num++;
if(vis[i]>=3)num+=3;
}
vi X(num),Y(num);
vi S(m+1,-1);
vi curr(m+1,1);
int cnt=1;
for(int i=0;i<n;i++){
if(vis[A[i]]==1){
if(i==n-1){
C[A[i]]=0;
}else{
C[A[i]]=A[i+1];
}
}
if(vis[A[i]]==2){
if(S[A[i]]==-1){
S[A[i]]=cnt;
C[A[i]]=-cnt;
X[cnt-1]=A[i+1];
cnt++;
}else{
int aux=S[A[i]];
if(i==n-1){
Y[aux-1]=0;
}else{
Y[aux-1]=A[i+1];
}
}
}
if(vis[A[i]]==3){
if(S[A[i]]==-1){
C[A[i]]=-cnt;
X[cnt-1]=-(cnt+1);
X[cnt]=-cnt;
Y[cnt-1]=-(cnt+2);
X[cnt+1]=A[i+1];
S[A[i]]=cnt;
cnt+=3;
curr[A[i]]=3;
}else{
if(curr[A[i]]==3){
int aux=S[A[i]];
Y[aux]=A[i+1];
curr[A[i]]=4;
}else{
int aux=S[A[i]];
if(i==n-1){
Y[aux+1]=0;
}else{
Y[aux+1]=A[i+1];
}
}
}
}
if(vis[A[i]]==4){
if(S[A[i]]==-1){
S[A[i]]=cnt;
C[A[i]]=-cnt;
X[cnt-1]=-(cnt+1);
Y[cnt-1]=-(cnt+2);
X[cnt]=A[i+1];
cnt+=3;
curr[A[i]]=2;
}else{
int aux=S[A[i]];
if(curr[A[i]]==2){
X[aux+1]=A[i+1];
}
if(curr[A[i]]==3){
Y[aux]=A[i+1];
}
if(curr[A[i]]==4){
if(i==n-1){
Y[aux+1]=0;
}else{
Y[aux+1]=A[i+1];
}
}
curr[A[i]]++;
}
}
}
/*for(int i=0;i<=m;i++){
cout<<C[i]<<" ";
}
cout<<endl;
for(int i=0;i<X.size();i++){
cout<<-(i+1)<<" "<<X[i]<<" "<<Y[i]<<endl;
}*/
answer(C, X, Y);
}
//3 4 1 2 1 3
//4 4 1 2 1 3
//4 10 1 2 1 3 1 2 3 3 4 3
//3 7 2 1 3 2 2 3 1
// la buena 2 5 1 2 2 2 2
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |