Submission #211828

#TimeUsernameProblemLanguageResultExecution timeMemory
211828MarcoMeijerArranging Shoes (IOI19_shoes)C++14
100 / 100
476 ms148088 KiB
#include <bits/stdc++.h> using namespace std; //macros typedef long long ll; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define INF 1e9 #define pb push_back #define fi first #define se second mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MX = 2e5; int n; map<int, queue<int>> first; int remPos[MX]; void addRemPos(int i, int x) { for(i++; i<=n; i+=i&-i) remPos[i] += x; } int getRemPos(int i) { int ans=0; for(i++; i>0; i-=i&-i) ans += remPos[i]; return ans; } void addRemPos(int i, int j, int x) { addRemPos(j+1,-x); addRemPos(i,x); } ll count_swaps(vi S) { n = S.size(); ll ans=0; RE(i,n+1) remPos[i] = 0; RE(i,n) { if(first[-S[i]].size()) { int pos = first[-S[i]].front(); first[-S[i]].pop(); ans += i-pos-getRemPos(pos)-1; if(S[i] < 0) ans++; addRemPos(pos,i,1); } else { first[S[i]].push(i); } } 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...