Submission #317990

#TimeUsernameProblemLanguageResultExecution timeMemory
317990Drew_Arranging Shoes (IOI19_shoes)C++14
100 / 100
124 ms71696 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; int const N = 1e5 + 7; int bit[2*N] = {}; void add(int x, int val) { x++; while (x < 2*N) bit[x] += val, x += (x & -x); } int sum(int x) { x++; int res = 0; while (x) res += bit[x], x -= (x & -x); return res; } queue<int> q[N]; bool type[N]; //false: left, true: right long long count_swaps(std::vector<int> s) { long long res = 0; for (int i = 0; i < s.size(); ++i) { if (q[abs(s[i])].empty() || !type[abs(s[i])] && s[i] < 0 || type[abs(s[i])] && s[i] > 0) { q[abs(s[i])].push(i); if (s[i] < 0) type[abs(s[i])] = false; else type[abs(s[i])] = true; } else { int target = q[abs(s[i])].front(); q[abs(s[i])].pop(); //cout << i << " -> " << target << ", shifted: " << sum(target) << ", cost: " << i - target - sum(target) << '\n'; res += i - target - sum(target); if (s[i] > 0) res--; add(target, 1); add(i, -1); } } return res; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for (int i = 0; i < s.size(); ++i)
      |                  ~~^~~~~~~~~~
shoes.cpp:32:48: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   32 |   if (q[abs(s[i])].empty() || !type[abs(s[i])] && s[i] < 0 || type[abs(s[i])] && s[i] > 0)
      |                               ~~~~~~~~~~~~~~~~~^~~~~~~~~~~
shoes.cpp:32:79: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   32 |   if (q[abs(s[i])].empty() || !type[abs(s[i])] && s[i] < 0 || type[abs(s[i])] && s[i] > 0)
      |                                                               ~~~~~~~~~~~~~~~~^~~~~~~~~~~
#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...