Submission #397754

#TimeUsernameProblemLanguageResultExecution timeMemory
397754ivan24Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; using ll = long long int; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll,ll> ii; typedef vector<ii> vii; typedef vector<vii> vvii; #define F first #define S second class SegmentTree { private: ll n; vi st,data; ll left(ll x){ return (x << 1); } ll right(ll x){ return ((x << 1) + 1); } void build (ll i, ll l, ll r){ if (l == r){ st[i] = data[l]; }else{ ll m = (l+r)/2; build (left(i),l,m); build (right(i),m+1,r); } } ll query (ll i, ll l, ll r, ll ql, ll qr){ if (qr >= r && l >= ql){ return st[i]; }else if (ql > r || l > qr){ return 0; }else{ ll m = (l+r)/2; ll ans = 0; ans += query(left(i),l,m,ql,qr); ans += query(right(i),m+1,r,ql,qr); return ans; } } void update (ll i, ll l, ll r, ll idx, ll dx){ if (r >= idx && idx >= l){ if (r == l){ st[i] += dx; }else{ ll m = (l+r)/2; update(left(i),l,m,idx,dx); update(right(i),m+1,r,idx,dx); st[i] = st[left(i)] + st[right(i)]; } } } public: SegmentTree (const vi& _data): data(_data){ n = data.size(); st.resize(4*n); } ll query (ll l, ll r){ return query(1,0,n-1,l,r); } void update (ll idx, ll dx){ update(1,0,n-1,idx,dx); } }; map<ll,set<ll> > byVals; long long count_swaps(vector<int> s) { ll n; n = s.size(); n /= 2; ll ans = 0; SegmentTree st(vi(2*n,0)); set<ll> available; for (ll i = 0; 2*n > i; i++){ if (byVals.find(s[i]) == byVals.end()) byVals[s[i]] = set<ll>() ; byVals[s[i]].insert(i); available.insert(i); } for (ll i = 0; n > i; i++){ ll ptr = *available.begin(); ll ptr2 = *byVals[-s[ptr]].begin(); ll modptr = st.query(0,ptr)+ptr; ll modptr2 = st.query(0,ptr2)+ptr2; ans += modptr2-1; if (s[ptr] > 0) ans++; //cout << ptr << ' ' << ptr2 << ' ' << modptr << ' ' << modptr2 << endl; available.erase(ptr); available.erase(ptr2); byVals[s[ptr]].erase(ptr); byVals[s[ptr2]].erase(ptr2); st.update(ptr,-1); st.update(ptr2,-1); } return ans; } int main() { int n; assert(1 == scanf("%d", &n)); vector<int> S(2 * n); for (int i = 0; i < 2 * n; i++) assert(1 == scanf("%d", &S[i])); fclose(stdin); long long result = count_swaps(S); printf("%lld\n", result); fclose(stdout); return 0; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:86:12: warning: unused variable 'modptr' [-Wunused-variable]
   86 |         ll modptr = st.query(0,ptr)+ptr;
      |            ^~~~~~
/tmp/ccsIYkTb.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccS5GDFv.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status