제출 #533019

#제출 시각아이디문제언어결과실행 시간메모리
533019gun_ganArranging Shoes (IOI19_shoes)C++17
25 / 100
69 ms21404 KiB
#include <bits/stdc++.h> using namespace std; template <typename T> struct Fenwick { vector<T> t; T n; Fenwick(T n) : n(n) { t.resize(n); } T g(T r){ T ret = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ret += t[r]; return ret; } T sum(T l, T r){ return g(r) - g(l - 1); } void add(T i, T v){ for(;i < n; i = i | (i + 1)) t[i] += v; } }; long long count_swaps(vector<int> s){ long long n = s.size(), ans = 0; const int N = 1e5 + 1; vector<int> L[n + 1], R[n + 1]; for(int i=0;i<n;i++) { if(s[i] < 0) L[-s[i]].push_back(i); else R[s[i]].push_back(i); } Fenwick<long long> fw(n + 1); for(int i=0;i<n;i++) fw.add(i, 1); vector<pair<int,int>> v; for(int i=1;i<=n;i++) { for(int j=0;j<L[i].size();j++) { if(L[i] > R[i]) { ans++; swap(L[i], R[i]); } v.push_back({L[i][j], R[i][j]}); } } sort(v.begin(), v.end()); for(auto i : v) { ans += fw.sum(i.first + 1, i.second - 1); fw.add(i.second, -1); fw.add(i.first, -1); } return ans; } // signed main(){ // int n; // cin >> n; // vector<int> t(2*n); // for(int i=0;i<2*n;i++) cin >> t[i]; // cout << count_swaps(t) << '\n'; // }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:41:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int j=0;j<L[i].size();j++)
      |               ~^~~~~~~~~~~~
shoes.cpp:29:12: warning: unused variable 'N' [-Wunused-variable]
   29 |  const int N = 1e5 + 1;
      |            ^
#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...