Submission #1088329

#TimeUsernameProblemLanguageResultExecution timeMemory
1088329LucasLeArranging Shoes (IOI19_shoes)C++17
100 / 100
47 ms15820 KiB
#include "shoes.h" #include <cstdio> #include <algorithm> #include <vector> using namespace std; #define pii pair<int,int> vector<int>A[101000], B[101000]; int n, BIT[201000]; void Add(int a, int b) { while (a <= 2 * n) { BIT[a] += b; a += (a&-a); } } int Sum(int a){ int r = 0; while (a) { r += BIT[a]; a -= (a&-a); } return r; } vector<pii>V; long long count_swaps(std::vector<int> s) { int i, j; n = s.size() / 2; for (i = 0; i < 2 * n; i++) { if (s[i] < 0)A[-s[i]].push_back(i+1); else B[s[i]].push_back(i + 1); } long long res = 0; for (i = 1; i <= n; i++) { for (j = 0; j < A[i].size(); j++) { int t1 = A[i][j], t2 = B[i][j]; if (t1 > t2) { res++; swap(t1, t2); } V.push_back({ t1,t2 }); } } sort(V.begin(), V.end()); int s3 = 0; for (auto &t : V) { int s1 = Sum(t.first); int s2 = Sum(t.second); res += s2 - s1 + (s3 - s2) * 2; s3++; Add(t.second, 1); } return res; }

Compilation message (stderr)

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