이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
int Fenwick[200010], n;
void update(int pos, int val) { while(pos<=200000)Fenwick[pos]+=val, pos+=pos&-pos; }
int sum(int x) { int S = 0; while(x)S+=Fenwick[x],x-=x&-x; return S; }
int query(int l, int r) { return sum(r)-sum(l-1); }
long long count_swaps(vector<int> s)
{
n = (int)s.size()/2;
vector<pair<int,int> > ord[200010], v;
for(int i = 0; i < 2*n; i++) ord[abs(s[i])].push_back({s[i],i});
long long ans = 0;
for(int i = 1; i<=n; i++)
{
sort(ord[i].begin(), ord[i].end());
for(int j = 0; j < ord[i].size()/2; j++)
{
int l = ord[i][j].second, r = ord[i][j+ord[i].size()/2].second;
if(l>r) ans++, swap(l,r);
v.push_back({l+1,r+1});
}
}
sort(v.begin(),v.end());
for(int i = 1; i <= 2*n; i++) update(i,1);
for(auto u : v)
{
int l = u.first, r = u.second;
ans+=query(l,r), update(l,-1),update(r,-1);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:19:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int j = 0; j < ord[i].size()/2; j++)
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |