Submission #736677

#TimeUsernameProblemLanguageResultExecution timeMemory
736677bobthebuilderArranging Shoes (IOI19_shoes)C++17
100 / 100
59 ms13408 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define pb push_back #define lowb(x) (x&(-x)) #define ALL(x) x.begin(),x.end() #define pii pair<int,int> #define f first #define s second const int maxn=2e5+5; int pos[maxn]; #define ll long long vector<int> v[maxn]; int bit[maxn]; void upd(int x,int v){ while(x<maxn){ bit[x]+=v; x+=lowb(x); } } int query(int x){ int ans=0; while(x){ ans+=bit[x]; x-=lowb(x); } return ans; } long long count_swaps(std::vector<int> s) { int n=sz(s)/2; int cur=0; REP(i,2*n){ if(s[i]<0){ v[-s[i]].pb(i); } } REP1(i,n) reverse(ALL(v[i])); vector<pii> vv; REP(i,2*n){ if(s[i]>0){ int z=v[s[i]].back(); v[s[i]].pop_back(); int t=i; if(z>t) swap(z,t); vv.pb({z,t}); } } sort(ALL(vv)); REP(i,n){ auto x=vv[i]; if(s[x.f]>0) swap(x.f,x.s); pos[x.f]=2*i,pos[x.s]=2*i+1; } ll ans=0; REP(i,2*n){ ans+=i-query(pos[i]); upd(pos[i]+1,1); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:34:6: warning: unused variable 'cur' [-Wunused-variable]
   34 |  int cur=0;
      |      ^~~
#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...