Submission #519728

#TimeUsernameProblemLanguageResultExecution timeMemory
519728WongChun1234Arranging Shoes (IOI19_shoes)C++14
0 / 100
1072 ms134940 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=100050; int n,pt=0,bit[MAXN]; bool used[MAXN],rrl[MAXN]; queue<int> pos[MAXN],neg[MAXN]; ll ans; ll query(int num){ ll ret=0; for (int i=num;i;i-=(i&-i)){ ret+=bit[i]; } return ret; } void add(int num){ for (int i=num;i<=n;i+=(i&-i)){ bit[i]++; } } long long count_swaps(std::vector<int> s) { n=s.size(); for (int i=0;i<n;i++){ if (s[i]>0) pos[s[i]].push(i); else neg[-s[i]].push(i); } for (int i=0;i<n;i++){ if (used[i]) continue; rrl[pt++]=neg[abs(s[i])].front(); used[neg[abs(s[i])].front()]=1; rrl[pt++]=pos[abs(s[i])].front(); used[pos[abs(s[i])].front()]=1; } for (int i=n-1;i>=0;i--){ ans+=query(rrl[i]); add(rrl[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...