Submission #724006

#TimeUsernameProblemLanguageResultExecution timeMemory
724006sandry24Arranging Shoes (IOI19_shoes)C++17
50 / 100
322 ms297356 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second const int sz = 100005; vector<ll> BIT(sz); void add(int x, int delta){ for(; x < sz; x += x & -x) BIT[x] += delta; } ll sum(int x){ ll res = 0; for(; x > 0; x -= x & -x) res += BIT[x]; return res; } ll count_swaps(vi s){ map<ll, deque<ll>> m; int n = s.size(); vector<bool> marked(n); for(ll i = 0; i < n; i++) m[s[i]].pb(i); ll ans = 0; for(int i = 0; i < n; i++){ if(marked[i]) continue; ll need = -s[i]; ll ind = m[need].front(); m[need].pop_front(); m[s[i]].pop_front(); marked[i] = marked[ind] = 1; //cerr << s[i] << ' ' << i << ' ' << ind << ' ' << sum(ind) << '\n'; ans += (ind - i - 1) - (sum(ind) - sum(i)); if(s[i] > 0) ans++; add(ind+1, 1); //cout << ans << '\n'; } 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...