제출 #202345

#제출 시각아이디문제언어결과실행 시간메모리
202345a_playerArranging Shoes (IOI19_shoes)C++14
10 / 100
101 ms135032 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5+10; deque<int> d[2*MAXN]; bitset<2*MAXN> v; long long ft[2*MAXN]; int N; void update(int k,long long val){ int x=k+1; while(x<=N){ ft[x]+=val; x+=x&(-x); } } long long query(int k){ int x=k+1; long long s=0; while(x>0){ s+=ft[x]; x-=x&(-x); } return s; } long long count_swaps(vector<int> s) { N=s.size(); long long ans=0; for(int i=0;i<N;i++)d[s[i]+MAXN].push_back(i); for(int i=0;i<N;i++){ if(v[i])continue; d[s[i]+MAXN].pop_front(); int h=d[MAXN-s[i]].front(); d[MAXN-s[i]].pop_front(); v[i]=1; v[h]=1; ans+=query(h)-query(i); update(i,2); update(h,-1); if(s[i]>s[h])ans++; } 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...