Submission #519734

#TimeUsernameProblemLanguageResultExecution timeMemory
519734WongChun1234Arranging Shoes (IOI19_shoes)C++14
100 / 100
277 ms275088 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=200050; int n,pt=0,bit[MAXN],rrl[MAXN]; bool used[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+1;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; neg[abs(s[i])].pop(); rrl[pt++]=pos[abs(s[i])].front(); used[pos[abs(s[i])].front()]=1; pos[abs(s[i])].pop(); } for (int i=n-1;i>=0;i--){ ans+=query(rrl[i]+1); add(rrl[i]+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...