Submission #399234

#TimeUsernameProblemLanguageResultExecution timeMemory
399234_Avocado_Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int int64_t vector<int>seg; void update(int k, int v, int pos, int l, int r){ if(l == r){ seg[pos] = v; return; } else if(k <= (l+r)/2) update(k, v, pos*2, l, (r+l)/2); else update(k, v, pos*2+1, (l+r)/2+1, r); seg[pos] = seg[pos*2] + seg[pos*2+1]; } int query(int ql, int qr, int pos, int l, int r){ if(l >= ql && r <= qr) return seg[pos]; else if(l > qr || r < ql) return 0; else return query(ql, qr, pos*2, l, (l+r)/2) + query(ql, qr, pos*2+1, (l+r)/2+1, r); } long long count_swaps(std::vector<int>v){ int n = v.size(); map<int, queue<int>>mp; vector<int>shoes(n); int cur = 1; for(int i = 0; i<n; ++i){ if(v[i] < 0){ mp[v[i]].push(cur); shoes[i] = cur; cur += 2; } } for(int i = 0; i<n; ++i){ if(v[i] > 0){ shoes[i] = mp[-v[i]].front()+1; mp[-v[i]].pop(); } } //for(auto u: shoes) cout<<u<<" "; vector<vector<int>>fred(n); seg.assign(n*4, 0); for(int i = 0; i<n; ++i){ fred[i] = {shoes[i], i}; } sort(fred.begin(), fred.end()); reverse(fred.begin(), fred.end()); int ans = 0; for(int i = 0; i<n; ++i){ ans += query(0, fred[i][1], 1, 0, n-1); update(fred[i][1], 1, 1, 0, n-1); } return ans; }

Compilation message (stderr)

/tmp/ccpgd8fb.o: In function `main':
grader.cpp:(.text.startup+0x278): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status