Submission #895486

#TimeUsernameProblemLanguageResultExecution timeMemory
895486ByeWorldArranging Shoes (IOI19_shoes)C++14
100 / 100
187 ms275732 KiB
#include "shoes.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int MAXN = 2e5+20; int skip[MAXN]; queue <int> vec[2*MAXN]; int n; ll ans; int st[2*MAXN]; int que(int x){ int te = 0; for(; x>0; x-=x&(-x)) te += st[x]; return te; } void upd(int x, int y){ for(; x<=2*MAXN-10; x+=x&(-x)) st[x]+=y; } long long count_swaps(vector<int> s) { n = s.size(); for(int i=0; i<n; i++){ if(s[i] < 0) vec[MAXN-s[i]].push(i); else vec[s[i]].push(i); } //cout << vec[2].front() << "p\n"; for(int i=0; i<n; i++){ if(skip[i]) continue; if(s[i] < 0){ int idx = vec[-s[i]].front(); skip[idx] = 1; ans += (ll)(idx-i-1 - (que(idx)-que(i))); upd(idx, 1); //cout << i << ' '<< idx << " idx\n"; vec[-s[i]].pop(); vec[MAXN-s[i]].pop(); } else { int idx = vec[MAXN+s[i]].front(); skip[idx] = 1; ans += (ll)(idx-i - (que(idx)-que(i))); upd(idx, 1); //cout << i << ' '<< idx << " idx\n"; vec[MAXN+s[i]].pop(); vec[s[i]].pop(); } } 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...