Submission #395332

#TimeUsernameProblemLanguageResultExecution timeMemory
395332ja_kingyArranging Shoes (IOI19_shoes)C++14
50 / 100
63 ms12684 KiB
#include "shoes.h" using namespace std; const int mxN = 1e5+10; vector<int> of_type[2*mxN]; int bit[mxN]; void upd(int x) {for (x++; x<mxN; x+=x&-x) bit[x]++;} int qry(int x) { int res = 0; for (x++; x; x-=x&-x) res += bit[x]; return res; } long long count_swaps(std::vector<int> s) { long long ans = 0; for (int i = s.size(); i--;) { of_type[s[i]+mxN].push_back(i); } for (int i = 0; i < s.size(); ++i) { if (of_type[s[i]+mxN].size() && i == of_type[s[i]+mxN].back()) { int x = of_type[mxN-s[i]].back(); ans += x - i + (s[i] > 0) - qry(x) + qry(i) - 1; upd(x); of_type[s[i]+mxN].pop_back(); of_type[mxN-s[i]].pop_back(); } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for (int i = 0; i < s.size(); ++i) {
      |                  ~~^~~~~~~~~~
#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...