제출 #944719

#제출 시각아이디문제언어결과실행 시간메모리
944719PenguinsAreCuteArranging Shoes (IOI19_shoes)C++17
45 / 100
35 ms10260 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; using ll = long long; struct ft { vector<int> v; int n; ft(int _n): n(_n) {v.resize(n+1,0);} inline int lsb(int x) {return x&(-x);} void up(int x, int u) { for(;x<=n;x+=lsb(x)) v[x]+=u; } int qry(int x) { ll ans = 0; for(;x;x-=lsb(x)) ans += v[x]; return ans; } }; long long count_swaps(std::vector<int> s) { int n = s.size() / 2; vector<int> v, pos[n+1]; for(int i=0;i<2*n;i++) { if(s[i]<0) { v.push_back(i); v.push_back(0); } else pos[s[i]].push_back(i); } for(int i=1;i<=n;i++) reverse(pos[i].begin(),pos[i].end()); for(int i=0;i<2*n;i+=2) { v[i+1]=end(pos[-s[v[i]]])[-1]; pos[-s[v[i]]].pop_back(); } ll ans = 0; ft fenwick(2*n); for(int i=2*n;i--;) { ans += fenwick.qry(v[i]); fenwick.up(v[i]+1,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...