Submission #1011054

#TimeUsernameProblemLanguageResultExecution timeMemory
1011054rythm_of_knightArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" #include <bits/stdc++.h> #define ll long long using namespace std; struct Fenwick{ vector<int> tr; int sz; Fenwick(int N){ tr.resize(N+1); sz=N; } void add(ll i, ll x){ for (; i<=sz; i+=(-i&i)) tr[i]+=x; } ll get(ll i){ ll sum=0; for (; i; i-=(i&-i)) sum+=tr[i]; return sum; } }; long long count_swaps(vector<int> s) { int n = s.size(), x; ll ans = 0, res = 0; vector <int> v = s; // cin >> n; sgt st; st.init(n); Fenwick tr(n+2); vector <deque <int>> p(n + 1, deque <int>()), m(n + 1, deque <int>()); for (int i = 0; i < n; i++) { // cin >> x; x = v[i]; if (x > 0) { if (!m[x].empty()) { int it = m[x].front(); m[x].pop_front(); int l = it + tr.get(it+1), r = i; int j = i; while (abs(s[j]) != abs(s[j - 1]) || s[j - 1] > s[j]) swap(s[j], s[j - 1]), j--, res++; ans += r - l - 1; tr.add(l+1, 1); tr.add(r+2, -1); } else { p[x].push_back(i); } } else { x = -x; if (!p[x].empty()) { int j = i; while (abs(s[j]) != abs(s[j - 1]) || s[j - 1] > s[j]) swap(s[j], s[j - 1]), j--, res++; int it = p[x].front(); p[x].pop_front(); int l = it + tr.get(it+1), r = i; ans += r - l; tr.add(l+1, 1); tr.add(r+2, -1); } else { m[x].push_back(i); } } } // if (ans != res) { // cout << ans << ' ' << res << '\n'; // for (int &i : v) // cout << i << ' '; // cout << '\n'; // } return res; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:27:5: error: 'sgt' was not declared in this scope; did you mean 'sig_t'?
   27 |     sgt st;
      |     ^~~
      |     sig_t
shoes.cpp:28:5: error: 'st' was not declared in this scope; did you mean 's'?
   28 |     st.init(n);
      |     ^~
      |     s