Submission #826851

#TimeUsernameProblemLanguageResultExecution timeMemory
826851vjudge1Arranging Shoes (IOI19_shoes)C++17
100 / 100
272 ms25420 KiB
#include <bits/stdc++.h> #define ll long long #define forn(j, i, n) for(int i = j; i <= n; ++i) #define FOR(j, i, n) for(int i = j; i < n; ++i) #define f first #define s second #define pb push_back #define all(v) v.begin(), v.end() #define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); using namespace std; const int maxn=2e5+10; int n, fen[maxn]; void upd(int r, int val) { for(; r <= n; r = ((r + 1) | r)) { fen[r] += val; } } int get(int r) { int s = 0; for(; r >= 0; r = ((r + 1) & r) - 1) { s += fen[r]; } return s; } long long count_swaps(std::vector<int> S) { n = S.size(); map <int, vector <int> > mapp; vector <int> del(n, 0); for(int i = n-1; i >= 0; --i) { mapp[S[i]].pb(i); upd(i, 1); } ll ans = 0; FOR(0, i, n) { if(del[i]) continue; int pos = mapp[-S[i]].back(); mapp[-S[i]].pop_back(); mapp[S[i]].pop_back(); ans += get(pos)-get(i) - (S[i] < 0); del[pos] = 1; upd(pos, -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...