Submission #1051622

#TimeUsernameProblemLanguageResultExecution timeMemory
1051622TobArranging Shoes (IOI19_shoes)C++14
100 / 100
33 ms15644 KiB
#include <bits/stdc++.h> #include "shoes.h" #define F first #define S second using namespace std; typedef long long ll; const int N = 2e5 + 7; int fen[N]; vector <int> v[N]; void add(int x, int val) {for (x++; x < N; x += x & -x) fen[x] += val;} int get(int x) {int out = 0; for (x++; x; x -= x & -x) out += fen[x]; return out;} ll count_swaps(vector <int> a) { int n = a.size(); vector <int> pa(n, -1); for (int i = 0; i < n; i++) v[a[i]+n/2].push_back(i); for (int i = 0; i <= n; i++) { for (int j = 0; j < v[i].size(); j++) pa[min(v[i][j], v[n-i][j])] = max(v[i][j], v[n-i][j]); } ll res = 0; for (int i = 0; i < n; i++) { if (pa[i] == -1) continue; res += pa[i]-i-(a[i] < 0) - get(pa[i])+get(i); add(pa[i], 1); } return res; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for (int j = 0; j < v[i].size(); j++) pa[min(v[i][j], v[n-i][j])] = max(v[i][j], v[n-i][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...