Submission #282489

#TimeUsernameProblemLanguageResultExecution timeMemory
282489GREGOIRELCArranging Shoes (IOI19_shoes)C++14
65 / 100
137 ms71928 KiB
#include "shoes.h" #include <cmath> #include <iostream> #include <queue> using namespace std; const int MAX_SHOES = 1e5 + 1; const int T_MAX = 1 << 18; const int MID = 1 << 17; int lstType[MAX_SHOES]; int segTree[T_MAX]; queue<int> enCours[MAX_SHOES]; void addVal(int noeud, int deb, int fin, int curDeb, int curFin) { if(curDeb > fin || curFin < deb || curDeb > curFin) { return; } if(curDeb >= deb && curFin <= fin) { segTree[noeud]++; return; } int mid = (curDeb + curFin) / 2; addVal(noeud * 2, deb, fin, curDeb, mid); addVal(noeud * 2 + 1, deb, fin, mid + 1, curFin); } int getVal(int pos) { pos += MID; int result = 0; while(pos > 0) { result += segTree[pos]; pos /= 2; } return result; } long long count_swaps(vector<int> s) { int N = (int)s.size(); long long result = 0; for(int curShoes = 0; curShoes < N; curShoes++) { int taille = abs(s[curShoes]); int tp = abs(s[curShoes]) / s[curShoes]; if(enCours[taille].empty()) { enCours[taille].push(curShoes); lstType[taille] = tp; } else { if(lstType[taille] == tp) { enCours[taille].push(curShoes); } else { result += curShoes - enCours[taille].front(); result -= getVal(enCours[taille].front()); if(tp == 1) { result--; } addVal(1, enCours[taille].front(), curShoes, 0, MID - 1); enCours[taille].pop(); } } } return result; }
#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...