Submission #1226214

#TimeUsernameProblemLanguageResultExecution timeMemory
1226214abdelhakimSorting (IOI15_sorting)C++20
Compilation error
0 ms0 KiB
#include "sorting.h" #include <bits/stdc++.h> #define dbg(x) cerr << #x << ' ' <<x << endl; #define ll long long using namespace std; vector<ll> ind; vector<ll> dest; vector<ll> recip; vector<ll> s; void swp(ll i, ll j) { swap(s[i],s[j]); swap(ind[s[i]],ind[s[j]]); swap(dest[s[i]],dest[s[j]]); recip[dest[s[i]]]=s[i]; recip[dest[s[j]]]=s[j]; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { P[0] = 0; Q[0] = 0; ind.resize(N); dest.resize(N); recip.resize(N); for (int i=0;i<N;i++) { s.push_back(S[i]); } for (int i=0;i<N;i++) { ind[s[i]]=i; } vector<ll> l3iba(N); for (int i=0;i<N;i++) l3iba[i]=s[i]; for (int i=0;i<mid;i++) { swap(l3iba[X[i]],l3iba[Y[i]]); } for (int i=0;i<N;i++) { dest[l3iba[i]]=i; recip[dest[l3iba[i]]]=l3iba[i]; } ll cur=0; for (int i=0;i<M;i++) { P[i]=0; Q[i]=0; } for (int i=0;i<M;i++) { swap(s[X[i]],s[Y[i]]); swap(ind[s[X[i]]],ind[s[Y[i]]]); for (;cur<N;cur++) { if(dest[cur]!=cur) { P[i]=ind[cur]; Q[i]=ind[recip[cur]]; swp(P[i],Q[i]); cur++; break; } } } // cout << "here" << endl; // for (int i=0;i<M;i++) // { // cout << X[i] << ' ' << Y[i]; // } return M; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:34:32: error: 'mid' was not declared in this scope
   34 |                 for (int i=0;i<mid;i++)
      |                                ^~~