Submission #388619

#TimeUsernameProblemLanguageResultExecution timeMemory
388619cpp219Arranging Shoes (IOI19_shoes)C++14
100 / 100
371 ms410552 KiB
#pragma GCC optimization "Ofast" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") //#include "shoes.h" #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 3e5 + 6; const ll lim = 3e5 + 6; const ll inf = 1e9 + 7; typedef pair<ll,ll> LL; deque<ll> pos[N],neg[N]; ll bit[N]; bool was[N]; void upd(ll p,ll val){ for (ll i = p;i < N;i += i & -i) bit[i] += val; } ll Get(ll p){ ll res = 0; for (ll i = p;i > 0;i -= i & -i) res += bit[i]; return res; } ll Query(ll L,ll R){ return Get(R) - Get(L - 1); } ll Find(ll cond,ll id,ll x){ if (!cond) return *lower_bound(pos[id].begin(),pos[id].end(),x); return *lower_bound(neg[id].begin(),neg[id].end(),x); } ll count_swaps(vector<int> v){ ll n = v.size(),ans = 0; for (ll i = 0;i < n;i++){ ll now = v[i]; if (now > 0) pos[now].push_back(i); else neg[-now].push_back(i); } for (ll i = 0;i < n;i++){ if (was[i]) continue; ll now = v[i],nxt; if (now < 0){ nxt = Find(0,-now,i); ans += nxt - i - Query(i,nxt) - 1; pos[-now].pop_front(); neg[-now].pop_front(); } else{ nxt = Find(1,now,i); ans += nxt - i - Query(i,nxt); neg[now].pop_front(); pos[now].pop_front(); } was[nxt] = 1; upd(nxt,1); } //exit(0); return ans; } /* vector<int> v; ll n,x; int main(){ //ios_base::sync_with_stdio(0); //cin.tie(0), cout.tie(0); #define task "test" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n; for (ll i = 1;i <= 2*n;i++) cin>>x,v.push_back(x); cout<<count_swaps(v); } */

Compilation message (stderr)

shoes.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
shoes.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      |
#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...