Submission #965391

#TimeUsernameProblemLanguageResultExecution timeMemory
965391SyriusArranging Shoes (IOI19_shoes)C++14
100 / 100
202 ms275704 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; // #define int long long #define ll long long #define ff first #define ss second #define pint pair < int , int > #define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL) const int inf = 1e9 + 9; const int mxn = 2e5 + 2; const int mod = 1e9 + 7; ll fn[mxn]; void update(int x , int v) { for (; x < mxn; x += x&-x) { fn[x] += v; } } ll query(int l , int r) { ll ans = 0; l--; for (; r > 0; r -= r&-r) ans += fn[r]; for (; l > 0; l -= l&-l) ans -= fn[l]; return ans; } queue < ll > le[mxn] , ri[mxn]; bool b[mxn]; ll count_swaps(vector < int > v) { ll n = v.size() / 2; for (ll i = 0; i < 2*n; i++) { if (v[i] < 0) le[-v[i]].push(i); else ri[v[i]].push(i); update(i+1 , 1); } ll ans = 0; for (ll i = 0; i < 2*n; i++) { if (b[i]) continue; ll id; if (v[i] < 0) { id = ri[-v[i]].front(); ans += query(i+2 , id); update(id+1 , -1); } else { id = le[v[i]].front(); ans += query(i+2 , id) + 1; update(id+1 , -1); } ri[abs(v[i])].pop(); le[abs(v[i])].pop(); b[id] = 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...