이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
long long n,pos1[100005],now,pos2[100005],pt1,pt2;
long long ans1,ans2;
queue <long long> v[100005],v2[100005];
vector <long long> ct1,ct2,d1,d2;
void cntInv(int l,int r){
if (l == r);
else
{
int mid=(l+r)/2;
ct1.clear(); ct2.clear(); d1.clear(); d2.clear();
for (int i=l;i<=mid;i++){
ct1.push_back(pos1[i]);
ct2.push_back(pos2[i]);
}
sort(ct1.begin(),ct1.end()); sort(ct2.begin(),ct2.end());
reverse(ct1.begin(),ct1.end()); reverse(ct2.begin(),ct2.end());
for (int i=mid+1;i<=r;i++){
d1.push_back(pos1[i]);
d2.push_back(pos2[i]);
}
sort(d1.begin(),d1.end()); sort(d2.begin(),d2.end());
reverse(d1.begin(),d1.end()); reverse(d2.begin(),d2.end());
pt1=0; pt2=0;
for (int i=0;i<d1.size();i++){
while (pt1 < (int)ct1.size() && ct1[pt1] >= d1[i])
pt1++;
while (pt2 < (int)ct2.size() && ct2[pt2] >= d2[i])
pt2++;
ans1+=pt1;
ans2+=pt2;
}
cntInv(l,mid);
cntInv(mid+1,r);
}
}
long long count_swaps(std::vector<int> s) {
n=(long long)s.size();
for (int i=0;i<n;i++){
if(s[i] > 0)
v[s[i]].push(i);
else
v2[-s[i]].push(i);
}
for (int i=0;i<n;i++){
if (s[i] < 0){
pos1[i]=now;
pos1[v[-s[i]].front()]=now+1;
v[-s[i]].pop();
now+=2;
}
}
now=0;
for (int i=0;i<n;i++){
if (s[i] > 0){
pos2[i]=now+1;
pos2[v2[s[i]].front()]=now;
v2[s[i]].pop();
now+=2;
}
}
cntInv(0,n-1);
cout << min(ans1,ans2) << "\n";
return 1;
}
/*int r,x;
vector <int> ori;
int main(){
cin >> r;
for (int i=0;i<r;i++){
cin >> x;
ori.push_back(x);
}
count_swaps(ori);
}*/
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'void cntInv(int, int)':
shoes.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i=0;i<d1.size();i++){
| ~^~~~~~~~~~
# | 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... |