Submission #1019275

#TimeUsernameProblemLanguageResultExecution timeMemory
1019275parsadox2Sorting (IOI15_sorting)C++17
100 / 100
123 ms34752 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; #define F first #define S second const int N = 2e5 + 10 , M = 6e5 + 10; int n , ar[N] , pos[N] , m , L[M] , R[M] , f[M] , s[M]; vector <pair<int , int>> vec; bool Check(int mid) { for(int i = 0 ; i < mid ; i++) swap(ar[L[i]] , ar[R[i]]); for(int i = 0 ; i < n ; i++) pos[ar[i]] = i; vec.clear(); for(int i = 0 ; i < n ; i++) if(ar[i] != i) { int p = pos[i]; swap(ar[i] , ar[p]); pos[ar[p]] = p; pos[ar[i]] = i; vec.push_back(make_pair(ar[i] , ar[p])); } return (vec.size() <= mid); } void Solve(int mid) { if(vec.size() < mid) vec.push_back(make_pair(0 , 0)); for(int i = 0 ; i < mid ; i++) { swap(ar[L[i]] , ar[R[i]]); swap(pos[ar[L[i]]] , pos[ar[R[i]]]); f[i] = pos[vec[i].F]; s[i] = pos[vec[i].S]; swap(ar[f[i]] , ar[s[i]]); swap(pos[ar[f[i]]] , pos[ar[s[i]]]); } } int findSwapPairs(int nn, int S[], int mm, int X[], int Y[], int P[], int Q[]) { n = nn; m = mm; for(int i = 0 ; i < m ; i++) { L[i] = X[i]; R[i] = Y[i]; } int low = -1 , high = m; while(high - low > 1) { for(int i = 0 ; i < n ; i++) { ar[i] = S[i]; pos[ar[i]] = i; } int mid = (low + high) >> 1; if(Check(mid)) high = mid; else low = mid; } for(int i = 0 ; i < n ; i++) { ar[i] = S[i]; pos[ar[i]] = i; } Check(high); for(int i = 0 ; i < n ; i++) { ar[i] = S[i]; pos[ar[i]] = i; } Solve(high); for(int i = 0 ; i < m ; i++) { P[i] = f[i]; Q[i] = s[i]; } return high; }

Compilation message (stderr)

sorting.cpp: In function 'bool Check(int)':
sorting.cpp:28:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |  return (vec.size() <= mid);
      |          ~~~~~~~~~~~^~~~~~
sorting.cpp: In function 'void Solve(int)':
sorting.cpp:33:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |  if(vec.size() < mid)
      |     ~~~~~~~~~~~^~~~~
#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...