Submission #364550

#TimeUsernameProblemLanguageResultExecution timeMemory
364550tiberiuArranging Shoes (IOI19_shoes)C++14
100 / 100
363 ms26732 KiB
#include "shoes.h" #include <map> #include <vector> using namespace std; const int MAX_N = 200001; int aib[MAX_N]; void update(int pos, int val) { pos++; while (pos < MAX_N) { aib[pos] += val; pos += (pos & -pos); } } int query(int pos) { pos++; int ans = 0; while (pos) { ans += aib[pos]; pos &= pos - 1; } return ans; } long long count_swaps(std::vector<int> s) { map<int, vector<int>> f; for (int i = 0; i < s.size(); i++) { f[s[i]].push_back(i); } long long ans = 0; vector<int> twin(s.size()); for (auto x : f) { if (x.first < 0) continue; for (int i = 0; i < f[x.first].size(); i++) { twin[f[x.first][i]] = f[-x.first][i]; twin[f[-x.first][i]] = f[x.first][i]; if (f[-x.first][i] > f[x.first][i]) ans++; } } for (int i = 0; i < s.size(); i++) { if (twin[i] < i) { ans += query(i) - query(twin[i]); update(i, 1); update(twin[i], 1); } } return ans; }

Compilation message (stderr)

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