제출 #143880

#제출 시각아이디문제언어결과실행 시간메모리
143880stoyan_malininArranging Shoes (IOI19_shoes)C++14
50 / 100
326 ms147620 KiB
#include<iostream> #include<cstring> #include<vector> #include<queue> #include<set> using namespace std; const int MAXN = 1e5 + 5; struct fenwickTree { int tree[MAXN*2]; fenwickTree() { memset(this->tree, 0, sizeof(this->tree)); } void update(int index, int value) { index++; while(index<MAXN) { this->tree[index] += value; index += index&(-index); } } int query(int index) { int sum = 0; index++; while(index>0) { sum += this->tree[index]; index -= index&(-index); } return sum; } }; fenwickTree *T = new fenwickTree(); queue <int> leftShoes[MAXN], rightShoes[MAXN]; int calcValue(int num, int index, int bestLeft, int bestRight) { int sum = (bestLeft - index) + (bestRight - (index+1)); if(bestLeft>bestRight) sum++; return sum; } long long count_swaps(vector <int> s) { set <int> allIndexes; for(int i = 0;i<s.size();i++) { allIndexes.insert(i); if(s[i]<0) leftShoes[ -s[i] ].push(i); else rightShoes[ s[i] ].push(i); } int answer = 0; for(int index = 0;index<s.size();index+=2) { int bestIndex = -1; int bestLeft, bestRight; bestIndex = abs(s[*allIndexes.begin()]); allIndexes.erase(leftShoes[bestIndex].front()); allIndexes.erase(rightShoes[bestIndex].front()); bestLeft = leftShoes[bestIndex].front() - T->query(leftShoes[bestIndex].front()); bestRight = rightShoes[bestIndex].front() - T->query(rightShoes[bestIndex].front()); T->update(leftShoes[bestIndex].front(), 1); T->update(rightShoes[bestIndex].front(), 1); leftShoes[bestIndex].pop(); rightShoes[bestIndex].pop(); //cout << bestLeft << " " << bestRight << '\n'; answer += calcValue(bestIndex, 0, bestLeft, bestRight); } //for(int i = 0;i<s.size();i++) cout << s[i] << " "; //cout << '\n'; return answer; }

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:59:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<s.size();i++)
                   ~^~~~~~~~~
shoes.cpp:68:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int index = 0;index<s.size();index+=2)
                       ~~~~~^~~~~~~~~
#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...