Submission #640186

#TimeUsernameProblemLanguageResultExecution timeMemory
640186ymmArranging Shoes (IOI19_shoes)C++17
10 / 100
4 ms5008 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 = 100'010; static vector<int> l[N], r[N]; static int frw[N]; __attribute__((optimize("O3,unroll-loops"),target("avx"))) static void add(int l, int r) { Loop (i,l,r) frw[i] += 1; } 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].back() - frw[r[-x].back()]; add(r[-x].back(), i); r[-x].pop_back(); } else { l[-x].push_back(i); } } else { if (l[x].size()) { ans += i - l[x].back() - frw[l[x].back()]- 1; add(l[x].back(), i); l[x].pop_back(); } else { r[x].push_back(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:23:2: note: in expansion of macro 'Loop'
   23 |  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...