제출 #1047288

#제출 시각아이디문제언어결과실행 시간메모리
1047288Onur_IlgazArranging Shoes (IOI19_shoes)C++17
50 / 100
273 ms146620 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; struct fw { int n; vector <int> t; fw(int size): n(size), t(n + 1) {} void update(int ind, int x) { while(ind <= n) { t[ind] += x; ind += ind & (-ind); } } int query(int ind) { int ans = 0; while(ind) { ans += t[ind]; ind -= ind & (-ind); } return ans; } }; long long count_swaps(std::vector<int> s) { fw t(s.size()); map <int, queue<int> > mp; int ans = 0; for(int i = 0; i < s.size(); i++) { if(!mp[-s[i]].empty()) { int ind = mp[-s[i]].front(); t.update(ind + 2, 1); t.update(i + 1, -1); ind += t.query(ind + 1); // cout << i << " " << ind << "\n"; mp[-s[i]].pop(); ans += (i - ind) - (s[i] > 0); } else { mp[s[i]].push(i); } } return ans; }

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

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