Submission #644402

#TimeUsernameProblemLanguageResultExecution timeMemory
644402a_aguiloArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms340 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; int N; void change(int index, int delta, int BIT[]){ for(; index <N; index += (index&(-index))){ BIT[index]+=delta; } } int query(int index, int BIT[]){ int ans = 0; for(; index > 0; index -= (index&(-index))) ans+= BIT[index]; return ans; } long long count_swaps(vector<int> s) { map<int, vector<int>> M; N = s.size()+1; int BIT[N]; memset(BIT, 0, sizeof(BIT)); for(int i = 1; i < N; ++i) change(i, 1, BIT); long long ans = 0; for(int i = 0; i < s.size(); ++i){ //cout << i << " " << ans << endl; if(M.find(-s[i]) == M.end()){ if(M.find(s[i]) == M.end()){ M[s[i]] = {i}; } else if(M[s[i]].empty()){ M[s[i]] = {i}; } else{ M[s[i]].push_back(i); } } else if(M[-s[i]].empty()){ if(M.find(s[i]) == M.end()){ M[s[i]] = {i}; } else if(M[s[i]].empty()){ M[s[i]] = {i}; } else{ M[s[i]].push_back(i); } } else{ if(s[i] < 0) ans++; //cout << "a "; int prev = M[-s[i]].back(); //cout <<"b "; M[-s[i]].pop_back(); //cout <<"c "; ans += (long long)query(i, BIT)-(long long)query(prev+1, BIT); //cout <<"d "; change(i+1, -1, BIT); //cout << "e "; change(prev+1, 1, BIT); } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     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...