Submission #292124

#TimeUsernameProblemLanguageResultExecution timeMemory
292124PeppaPigArranging Shoes (IOI19_shoes)C++14
100 / 100
107 ms20464 KiB
#include "shoes.h" #include <bits/stdc++.h> #define long long long #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 2e5 + 5; int t[N]; void update(int x, int k) { for(int i = x; i < N; i += i & -i) t[i] += k; } int query(int x, int ret = 0) { for(int i = x; i; i -= i & -i) ret += t[i]; return ret; } int n; long ans = 0; vector<int> l[N], r[N]; long count_swaps(vector<int> s) { n = (int)s.size(); for(int i = 0; i < n; i++) { if(s[i] < 0) l[-s[i]].emplace_back(i + 1); else r[s[i]].emplace_back(i + 1); } vector<pii> vec; for(int i = 1; i <= n; i++) for(int j = 0; j < l[i].size(); j++) { int x = l[i][j], y = r[i][j]; if(x > y) swap(x, y), ++ans; vec.emplace_back(x, y); } sort(vec.begin(), vec.end()); for(int i = 1; i <= n; i++) update(i, 1); for(pii p : vec) { ans += query(p.x) + query(p.y) - 3; update(p.x, -1), update(p.y, -1); } return ans; }

Compilation message (stderr)

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