Submission #69395

#TimeUsernameProblemLanguageResultExecution timeMemory
69395yusufakeSorting (IOI15_sorting)C++98
100 / 100
537 ms13048 KiB
#include<bits/stdc++.h>
using namespace std;
#include "sorting.h"

#define pb push_back
#define mp make_pair
#define mx 200005
int T[mx],W[mx],A[mx],B[mx],i,l,m,r,t;
int findSwapPairs(int n, int *S, int M, int *X, int *Y, int *P, int *Q){
    l = 0;
    r = n;
for(; l<r ;){
    m = l+r >> 1;
    for(i=0;i<n;i++){
        W[ S[i] ] = i;
        T[i] = S[i];
        P[i] = Q[i] = 0;
    }
    for(i=0;i<m;i++)
        swap(T[ X[i] ], T[ Y[i] ]);
    t = 0;
    for(i=0;i<n;i++)
        for(; T[i] != i ; ){
            A[t] = T[ T[i] ];
            B[t] = T[i];
            t++;
            swap(T[ T[i] ] , T[i]);
        }
    for(i=0;i<n;i++) T[i] = S[i];
    for(i=0;i<m;i++){
        swap(T[ X[i] ] , T[ Y[i] ]);
        swap(W[ T[ X[i] ] ] , W[ T[ Y[i] ] ]);
        if(i >= t) continue;
        swap(T[ W[ A[i] ] ] , T[ W[ B[i] ] ]);
        P[i] = W[ A[i] ];
        Q[i] = W[ B[i] ];
        swap(W[ A[i] ] , W[ B[i] ]);
    }
    if(t > m) l = m+1;
    else r = m;
}
///
m = l;
    for(i=0;i<n;i++){
        W[ S[i] ] = i;
        T[i] = S[i];
        P[i] = Q[i] = 0;
    }
for(i=0;i<m;i++)
swap(T[ X[i] ], T[ Y[i] ]);
t = 0;
for(i=0;i<n;i++)
for(; T[i] != i ; ){
    A[t] = T[ T[i] ];
    B[t] = T[i];
    t++;
    swap(T[ T[i] ] , T[i]);
}
for(i=0;i<n;i++) T[i] = S[i];
for(i=0;i<m;i++){
    swap(T[ X[i] ] , T[ Y[i] ]);
    swap(W[ T[ X[i] ] ] , W[ T[ Y[i] ] ]);
    if(i >= t) continue;
    swap(T[ W[ A[i] ] ] , T[ W[ B[i] ] ]);
    P[i] = W[ A[i] ];
    Q[i] = W[ B[i] ];
    swap(W[ A[i] ] , W[ B[i] ]);
}

    return l;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:13:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     m = l+r >> 1;
         ~^~
sorting.cpp:9:38: warning: unused parameter 'M' [-Wunused-parameter]
 int findSwapPairs(int n, int *S, int M, int *X, int *Y, int *P, int *Q){
                                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...