Submission #736669

#TimeUsernameProblemLanguageResultExecution timeMemory
736669bobthebuilderArranging Shoes (IOI19_shoes)C++17
45 / 100
38 ms11212 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() 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){ pos[i]=2*cur; v[-s[i]].pb(cur); ++cur; } } REP1(i,n) reverse(ALL(v[i])); REP(i,2*n){ if(s[i]>0){ pos[i]=2*v[s[i]].back()+1; v[s[i]].pop_back(); } } ll ans=0; REP(i,2*n){ ans+=i-query(pos[i]); upd(pos[i]+1,1); } return ans; }
#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...