Submission #958804

#TimeUsernameProblemLanguageResultExecution timeMemory
958804MuntherCarrotArranging Shoes (IOI19_shoes)C++14
100 / 100
47 ms15036 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; #define ll long long const int MAXN = 2e5 + 10; int bit[MAXN]; void upd(int i, int val){ for(i++; i <= MAXN; i += -i & i){ bit[i - 1] += val; } } ll clc(int i){ ll res = 0; for(i++; i > 0; i -= -i & i){ res += bit[i - 1]; } return res; } ll clc(int l, int r){ return clc(r) - clc(l - 1); } long long count_swaps(vector<int> s) { ll res = 0; int n = s.size(); vector<vector<int>> vec(n + 1); for(int i = n - 1; i >= 0; i--){ vec[s[i] + n / 2].push_back(i); } for(int i = 0; i < n; i++){ if(vec[s[i] + n / 2].back() != i) continue; int x = vec[-s[i] + n / 2].back(); vec[s[i] + n / 2].pop_back(); vec[-s[i] + n / 2].pop_back(); res += x - i - (s[i] < 0) - clc(i, x); upd(i, 1); upd(x, 1); } return res; }
#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...