Submission #1098443

#TimeUsernameProblemLanguageResultExecution timeMemory
1098443alexander707070Sorting (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include "sorting.h" #define MAXN 200007 using namespace std; int n,m,q,br; int pos[MAXN],s[MAXN],post[MAXN]; int to[MAXN]; int check(int stop){ for(int i=0;i<n;i++)s[i]=i; for(int i=0;i<stop;i++)swap(s[X[i]],s[Y[i]]); for(int i=0;i<n;i++)to[s[i]]=i; for(int i=0;i<n;i++){ s[i]=S[i]; pos[s[i]]=i; post[to[i]]=i; } int pt=0; for(int i=0;i<stop;i++){ P[i]=Q[i]=0; swap(s[X[i]],s[Y[i]]); swap(to[X[i]],to[Y[i]]); swap(pos[s[X[i]]],pos[s[Y[i]]]); swap(post[to[X[i]]],post[to[Y[i]]]); while(pt<n and to[pos[pt]]==pt)pt++; if(pt==n)continue; P[i]=pos[pt]; Q[i]=post[pt]; swap(s[P[i]],s[Q[i]]); swap(pos[s[P[i]]],pos[s[Q[i]]]); } q=stop; br=0; for(int i=0;i<n;i++){ s[i]=S[i]; if(s[i]==i)br++; } for(int i=0;i<stop;i++){ if(br==n)return i; if(s[X[i]]==X[i])br--; if(s[Y[i]]==Y[i])br--; swap(s[X[i]],s[Y[i]]); if(s[X[i]]==X[i])br++; if(s[Y[i]]==Y[i])br++; if(s[P[i]]==P[i])br--; if(s[Q[i]]==Q[i])br--; swap(s[P[i]],s[Q[i]]); if(s[P[i]]==P[i])br++; if(s[Q[i]]==Q[i])br++; } if(br==n)return q; return -1; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; m=M; int l=-1,r=n,tt; while(l+1<r){ int tt=(l+r)/2; if(check(tt)!=-1){ r=tt; }else{ l=tt; } } return check(r); }

Compilation message (stderr)

sorting.cpp: In function 'int check(int)':
sorting.cpp:14:32: error: 'X' was not declared in this scope
   14 |  for(int i=0;i<stop;i++)swap(s[X[i]],s[Y[i]]);
      |                                ^
sorting.cpp:14:40: error: 'Y' was not declared in this scope
   14 |  for(int i=0;i<stop;i++)swap(s[X[i]],s[Y[i]]);
      |                                        ^
sorting.cpp:18:8: error: 'S' was not declared in this scope
   18 |   s[i]=S[i]; pos[s[i]]=i;
      |        ^
sorting.cpp:24:3: error: 'P' was not declared in this scope
   24 |   P[i]=Q[i]=0;
      |   ^
sorting.cpp:24:8: error: 'Q' was not declared in this scope
   24 |   P[i]=Q[i]=0;
      |        ^
sorting.cpp:26:10: error: 'X' was not declared in this scope
   26 |   swap(s[X[i]],s[Y[i]]);
      |          ^
sorting.cpp:26:18: error: 'Y' was not declared in this scope
   26 |   swap(s[X[i]],s[Y[i]]);
      |                  ^
sorting.cpp:43:8: error: 'S' was not declared in this scope
   43 |   s[i]=S[i];
      |        ^
sorting.cpp:50:8: error: 'X' was not declared in this scope
   50 |   if(s[X[i]]==X[i])br--;
      |        ^
sorting.cpp:51:8: error: 'Y' was not declared in this scope
   51 |   if(s[Y[i]]==Y[i])br--;
      |        ^
sorting.cpp:53:10: error: 'X' was not declared in this scope
   53 |   swap(s[X[i]],s[Y[i]]);
      |          ^
sorting.cpp:53:18: error: 'Y' was not declared in this scope
   53 |   swap(s[X[i]],s[Y[i]]);
      |                  ^
sorting.cpp:58:8: error: 'P' was not declared in this scope
   58 |   if(s[P[i]]==P[i])br--;
      |        ^
sorting.cpp:59:8: error: 'Q' was not declared in this scope
   59 |   if(s[Q[i]]==Q[i])br--;
      |        ^
sorting.cpp:61:10: error: 'P' was not declared in this scope
   61 |   swap(s[P[i]],s[Q[i]]);
      |          ^
sorting.cpp:61:18: error: 'Q' was not declared in this scope
   61 |   swap(s[P[i]],s[Q[i]]);
      |                  ^
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:78:7: warning: declaration of 'tt' shadows a previous local [-Wshadow]
   78 |   int tt=(l+r)/2;
      |       ^~
sorting.cpp:76:15: note: shadowed declaration is here
   76 |  int l=-1,r=n,tt;
      |               ^~
sorting.cpp:76:15: warning: unused variable 'tt' [-Wunused-variable]
sorting.cpp:73:30: warning: unused parameter 'S' [-Wunused-parameter]
   73 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                          ~~~~^~~
sorting.cpp:73:46: warning: unused parameter 'X' [-Wunused-parameter]
   73 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
sorting.cpp:73:55: warning: unused parameter 'Y' [-Wunused-parameter]
   73 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                   ~~~~^~~
sorting.cpp:73:64: warning: unused parameter 'P' [-Wunused-parameter]
   73 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                            ~~~~^~~
sorting.cpp:73:73: warning: unused parameter 'Q' [-Wunused-parameter]
   73 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                                     ~~~~^~~