Submission #599603

#TimeUsernameProblemLanguageResultExecution timeMemory
599603beaconmcSorting (IOI15_sorting)C++14
Compilation error
0 ms0 KiB
#pragma GCC optimize("O3") #include "sorting.h" #include <bits/stdc++.h> typedef long long ll; #define ll int using namespace std; #define FOR(i, x, y) for(ll i=x; i<y; i++) #define FORNEG(i, x, y) for(ll i=x; i>y; i--) #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL) ll n,s[600001],m,x[600001],y[600001],p[600001],q[600001]; vector<vector<ll>> temp; int32 check(ll k){ vector<ll> sus; unordered_map<ll, ll> realsus; temp.clear(); FOR(i,0,n){ sus.push_back(s[i]); realsus[s[i]] = i; } FOR(i,0,k){ swap(realsus[sus[x[i]]], realsus[sus[y[i]]]); swap(sus[x[i]], sus[y[i]]); } cout << endl; ll ans = 0; FOR(i,0,n){ if (realsus[i]==i) continue; ans++; ll amogus = sus[i]; temp.push_back({i, sus[i]}); swap(sus[realsus[i]], sus[i]); swap(realsus[i], realsus[amogus]); } if (ans<k){ FOR(i,0,k-ans){ temp.push_back({0,0}); } } if (ans <= k) return 1; else return 0; } void genans(ll k){ vector<ll> sus; unordered_map<ll, ll> realsus; FOR(i,0,n){ sus.push_back(s[i]); realsus[s[i]] = i; } FOR(i,0,k){ swap(realsus[sus[x[i]]], realsus[sus[y[i]]]); swap(sus[x[i]], sus[y[i]]); p[i] = realsus[temp[i][0]]; q[i] = realsus[temp[i][1]]; swap(sus[realsus[temp[i][0]]], sus[realsus[temp[i][1]]]); swap(realsus[temp[i][0]], realsus[temp[i][1]]); } } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N; FOR(i,0,n){ s[i] = S[i]; } m = M; FOR(i,0,m){ x[i] = X[i]; y[i] = Y[i]; } ll lo = 0; ll hi = n+1; while (lo<hi){ int mid = lo + (hi - lo) / 2; if (check(mid)) { hi = mid; } else { lo = mid + 1; } } check(lo); genans(lo); FOR(i,0,lo){ P[i] = p[i]; Q[i] = q[i]; } return lo; }

Compilation message (stderr)

sorting.cpp:18:1: error: 'int32' does not name a type; did you mean 'int32_t'?
   18 | int32 check(ll k){
      | ^~~~~
      | int32_t
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:93:7: error: 'check' was not declared in this scope
   93 |   if (check(mid)) {
      |       ^~~~~
sorting.cpp:99:2: error: 'check' was not declared in this scope
   99 |  check(lo);
      |  ^~~~~