제출 #644407

#제출 시각아이디문제언어결과실행 시간메모리
644407a_aguiloArranging Shoes (IOI19_shoes)C++14
100 / 100
344 ms75948 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, queue<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]] = queue<int>({i}); } else if(M[s[i]].empty()){ M[s[i]] = queue<int>({i}); } else{ M[s[i]].push(i); } } else if(M[-s[i]].empty()){ if(M.find(s[i]) == M.end()){ M[s[i]] = queue<int>({i}); } else if(M[s[i]].empty()){ M[s[i]] = queue<int>({i}); } else{ M[s[i]].push(i); } } else{ if(s[i] < 0) ans++; //cout << "a "; int prev = M[-s[i]].front(); //cout <<"b "; M[-s[i]].pop(); //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; }

컴파일 시 표준 에러 (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...