Submission #609370

#TimeUsernameProblemLanguageResultExecution timeMemory
609370nyaruhodoArranging Shoes (IOI19_shoes)C++14
100 / 100
151 ms15660 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; // segtree or pbds ig vector<ll> seg; void psh(ll v){ seg[v*2] += seg[v]; seg[v*2+1] += seg[v]; seg[v]=0; } void update(ll v,ll l,ll r,ll tl,ll tr){ if(l > r) return; if(tl==l && tr == r) { seg[v]++; return; } ll tm=(tl+tr)/2; update(v*2,l,min(r,tm),tl,tm); update(v*2+1,max(l,tm+1),r,tm+1,tr); } ll query(ll v,ll tl,ll tr,ll s){ if(tl==tr && tl==s) return seg[v]; psh(v); ll tm=(tl+tr)/2; if(s <= tm) return query(v*2,tl,tm,s); else return query(v*2+1,tm+1,tr,s); } long long count_swaps(std::vector<int> s) { set<pair<ll,ll>> st; // val, pos ll cnt=0,n=s.size(); seg.resize(4*(n+10),0); for(ll i = 0;i < s.size();i++){ auto lb = st.lower_bound({-s[i],-1}); if(lb == st.end() || lb->first!=-s[i]){ st.insert({s[i],i}); continue; } auto p = *lb; st.erase(lb); ll add = query(1,1,n,p.second+1); cnt+=i-(p.second+add)-1; update(1,p.second+1,i+1,1,n); if(s[i]<0) cnt++; } return cnt; } /* */

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:43:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(ll i = 0;i < s.size();i++){
      |               ~~^~~~~~~~~~
#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...