이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
LL ans,ANS;
int n,id=1,used[200005];
vector<int> a,dr[200005],bc[200005];
void mergeSerge(int l,int r)
{
if(l>=r)
return;
int m=(l+r)/2;
mergeSerge(l,m);
mergeSerge(m+1,r);
vector<int> x,y;
for(int i=l;i<=m;i++)
x.PB(a[i]);
for(int i=m+1;i<=r;i++)
y.PB(a[i]);
int d=l;
int p=0,k=0;
while(p<x.size())
{
while(k<y.size() && y[k]<x[p])
{
ans+=(LL)(x.size()-p);
a[d++]=y[k++];
}
a[d++]=x[p++];
}
while(k<y.size())
a[d++]=y[k++];
}
LL count_swaps(vector<int> A)
{
a=A;
n=A.size()/2;
for(int i=0;i<a.size();i++)
{
if(a[i]>0)
dr[a[i]].PB(i);
else
bc[-a[i]].PB(i);
}
for(int i=1;i<=n;i++)
{
reverse(all(dr[i]));
reverse(all(bc[i]));
}
for(int i=0;i<a.size();i++)
if(!used[i])
{
int val=abs(a[i]);
if(a[i]<0)
{
used[i]=1;
used[dr[val].back()]=1;
a[i]=id++;
a[dr[val].back()]=id++;
}
else
{
used[i]=1;
used[bc[val].back()]=1;
a[bc[val].back()]=id++;
a[i]=id++;
}
dr[val].pop_back();
bc[val].pop_back();
}
// for(int i=0;i<a.size();i++)
// cout<<a[i]<<":";
// cout<<endl;
mergeSerge(0,2*n-1);
return ans;
}
//#define death
#ifdef death
int main()
{
int N;
cin>>N;
N*=2;
vector<int> X;
for(int i=0;i<N;i++)
{
int val=rand()%(N/2)+1;
cin>>val;
X.PB(val);
// X.PB(-val);
}
//random_shuffle(all(X));
cout<<count_swaps(X)<<endl;
return 0;
}
#endif // death
/*
3
-2 2 2 -2 -2 2
*/
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'void mergeSerge(int, int)':
shoes.cpp:46:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p<x.size())
~^~~~~~~~~
shoes.cpp:48:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(k<y.size() && y[k]<x[p])
~^~~~~~~~~
shoes.cpp:55:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(k<y.size())
~^~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:64:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a.size();i++)
~^~~~~~~~~
shoes.cpp:76:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a.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... |