Submission #145322

#TimeUsernameProblemLanguageResultExecution timeMemory
145322MvCArranging Shoes (IOI19_shoes)C++14
100 / 100
174 ms34552 KiB
#include "shoes.h" #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include<bits/stdc++.h> #define rc(x) return cout<<x<<endl,0 #define pb push_back #define mkp make_pair #define in insert #define er erase #define fd find #define fr first #define sc second typedef long long ll; typedef long double ld; const ll INF=0x3f3f3f3f3f3f3f3f; const ll llinf=(1LL<<62); const int inf=(1<<30); const int nmax=2e5+50; const int mod=1e9+7; using namespace std; int i,j,n,a[nmax],p[nmax],fw[nmax],c,vz[nmax]; set<int>v[2][nmax]; ll rs; void upd(int i) { for(;i<=n;i+=i&(-i))fw[i]++; } int qry(int i) { int ans=0; for(;i>=1;i-=i&(-i))ans+=fw[i]; return ans; } ll count_swaps(vector<int> s) { n=(int)s.size(); for(i=1;i<=n;i++) { a[i]=s[i-1]; if(a[i]<0)v[0][-a[i]].in(i); else v[1][a[i]].in(i); } for(i=1;i<=n;i++) { if(vz[i])continue; if(a[i]<0) { v[0][-a[i]].er(v[0][-a[i]].fd(i)); j=*v[1][-a[i]].begin(); v[1][-a[i]].er(v[1][-a[i]].begin()); vz[j]=1; p[i]=++c; p[j]=++c; } else { v[1][a[i]].er(v[1][a[i]].fd(i)); j=*v[0][a[i]].begin(); v[0][a[i]].er(v[0][a[i]].begin()); vz[j]=1; p[j]=++c; p[i]=++c; } } for(i=n;i>=1;i--) { rs+=1LL*qry(p[i]); upd(p[i]); } return rs; }

Compilation message (stderr)

shoes.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
shoes.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
#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...