제출 #774061

#제출 시각아이디문제언어결과실행 시간메모리
774061_martynasArranging Shoes (IOI19_shoes)C++14
100 / 100
65 ms16424 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; using ll = long long; ll count_swaps(vector<int> s) { int n = s.size()/2; vector<ll> fen(2*n+1); auto add = [&](int i, int x) { i++; while(i <= 2*n) { fen[i] += x; i += i&(-i); } }; auto get = [&](int i) { i++; ll sum = 0; while(i) { sum += fen[i]; i -= i&(-i); } return sum; }; for(int i = 0; i < 2*n; i++) { add(i, 1); } vector<int> to(2*n, -1); vector<vector<int>> where(2*n+3); for(int i = 0; i < 2*n; i++) { where[s[i]+n].push_back(i); } for(int i = 0; i < n; i++) { for(int j = 0; j < where[i].size(); j++) { int a = where[i][j], b = where[abs(i-n)+n][j]; if(a > b) swap(a, b); to[a] = b; } } ll ans = 0; for(int i = 0; i < 2*n; i++) { if(to[i] == -1) continue; int prev = ans; if(s[i] > 0) ans++; add(i, -1); add(to[i], -1); ans += get(to[i])-get(i); } return ans; }

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

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j = 0; j < where[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~~
shoes.cpp:45:13: warning: unused variable 'prev' [-Wunused-variable]
   45 |         int prev = ans;
      |             ^~~~
#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...