Submission #143900

#TimeUsernameProblemLanguageResultExecution timeMemory
143900RezwanArefin01Arranging Shoes (IOI19_shoes)C++17
0 / 100
278 ms269560 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; const int N = 2e5 + 10; deque<int> pos[N][2]; int r[N], bit[N]; void update(int x) { for(++x; x > 0; x -= x & -x) ++bit[x]; } int read(int x) { int ret = 0; for(++x; x < N; x += x & -x) ret += bit[x]; return ret; } long long count_swaps(vector<int> s) { exit(0); vector<int> ord; for(int i = 0; i < s.size(); ++i) { int x = abs(s[i]), c = s[i] > 0; if(pos[x][c ^ 1].size()) { r[pos[x][c ^ 1].front()] = i; pos[x][c ^ 1].pop_front(); } else { pos[x][c].push_back(i); ord.push_back(i); } } long long ans = 0; for(int i : ord) { int L = i + read(i); int R = r[i] + read(r[i]); ans += R - L - 1 + (s[i] > 0); update(R); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     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...