Submission #640190

#TimeUsernameProblemLanguageResultExecution timeMemory
640190ymmArranging Shoes (IOI19_shoes)C++17
100 / 100
219 ms273652 KiB
#include "shoes.h" #include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (r); ++x) #define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x) typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll , ll > pll; using namespace std; static const int N = 200'010; static queue<int> l[N], r[N]; static int fen[N]; static void add_fen(int r, int x) { while (r > 0) { fen[r] += x; r -= r & -r; } } static void add(int l, int r) { add_fen(r, 1); add_fen(l, -1); } static int get(int i) { ++i; int ans = 0; while (i < N) { ans += fen[i]; i += i & -i; } return ans; } long long count_swaps(std::vector<int> s) { ll ans = 0; Loop (i, 0, s.size()) { int x = s[i]; if (x < 0) { if (r[-x].size()) { ans += i - r[-x].front() - get(r[-x].front()); add(r[-x].front(), i); r[-x].pop(); } else { l[-x].push(i); } } else { if (l[x].size()) { ans += i - l[x].front() - get(l[x].front()) - 1; add(l[x].front(), i); l[x].pop(); } else { r[x].push(i); } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:3:40: 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]
    3 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
shoes.cpp:39:2: note: in expansion of macro 'Loop'
   39 |  Loop (i, 0, s.size()) {
      |  ^~~~
#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...