Submission #718603

#TimeUsernameProblemLanguageResultExecution timeMemory
718603myrcellaSorting (IOI15_sorting)C++17
36 / 100
2 ms468 KiB
//by szh #include<bits/stdc++.h> #include <unordered_map> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} #include "sorting.h" const int maxn = 6e5+10; int n,m; int a[maxn],b1[maxn],b[maxn]; pii ans[maxn]; pii p[maxn]; pii pos[maxn]; bool check(int cnt,bool flag) { rep(i,0,n) b1[i] = i; rep(i,0,cnt) swap(b1[p[i].fi],b1[p[i].se]); rep(i,0,n) pos[b1[i]].fi = i; rep(i,0,n) b[i] = a[i]; rep(i,0,n) pos[a[i]].se = i; int hi = 0; rep(i,0,cnt) { int x = p[i].fi,y=p[i].se; if (x!=y) { swap(b1[x],b1[y]); swap(b[x],b[y]); pos[b[x]].se = x,pos[b[y]].se = y; pos[b1[x]].fi = x,pos[b1[y]].fi = y; } pii cur = {0,0}; while (hi<n and pos[hi].fi==pos[hi].se) hi++; if (hi<n) cur = pos[hi]; x = cur.fi,y=cur.se; if (x!=y) { swap(b[x],b[y]); pos[b[x]].se = x,pos[b[y]].se = y; } ans[i] = cur; if (flag and hi==n) return true; } while (hi<n and pos[hi].fi==pos[hi].se) hi++; return hi==n; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N,m= M; int l=0,r=M; rep(i,0,n) a[i] =S[i]; rep(i,0,M) p[i] = {X[i],Y[i]}; while (l<r) { int mid=l+r>>1; if (check(mid,true)) r = mid; else l = mid+1; } check(l,false); rep(i,0,l) P[i] = ans[i].fi, Q[i] = ans[i].se; return l; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:72:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |   int mid=l+r>>1;
      |           ~^~
#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...