Submission #568494

#TimeUsernameProblemLanguageResultExecution timeMemory
568494stevancvArranging Shoes (IOI19_shoes)C++14
100 / 100
91 ms16532 KiB
#include <bits/stdc++.h> #include "shoes.h" #define ll long long #define ld long double #define sp ' ' #define en '\n' using namespace std; const int N = 1e5 + 2; const ll mod = 1e9 + 7; int bit[2 * N]; void Add(int x) { for (; x < 2 * N; x += x & (-x)) bit[x]++; } int Get(int x) { int ans = 0; for (; x > 0; x -= x & (-x)) ans += bit[x]; return ans; } long long count_swaps(vector<int> s) { int n = s.size() / 2; vector<vector<int>> pa(n), pb(n); for (int i = 0; i < 2 * n; i++) { if (s[i] > 0) { s[i] -= 1; pb[s[i]].push_back(i); } else { s[i] += 1; pa[abs(s[i])].push_back(i); } } ll ans = 0; vector<array<int, 2>> p; for (int i = 0; i < n; i++) { for (int j = 0; j < pa[i].size(); j++) { if (pa[i][j] > pb[i][j]) { swap(pa[i][j], pb[i][j]); ans += 1; } p.push_back({pa[i][j], pb[i][j]}); } } sort(p.begin(), p.end()); vector<int> all; for (int i = 0; i < n; i++) { all.push_back(p[i][0]); all.push_back(p[i][1]); } for (int i = all.size() - 1; i >= 0; i--) { ans += Get(all[i] + 1); Add(all[i] + 1); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int j = 0; j < pa[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...