이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5 + 10;
vector<pii> coord;
vector<int> l[N], r[N], s;
int n, arr[N];
long long ans, fen[N];
long long query( int x ) {
long long ret = 0;
for( int i = x ; i > 0 ; i -= i & -i ) ret += fen[i];
return ret;
}
void up( int x ) {
for( int i = x ; i < N ; i += i & -i ) fen[i] += 1;
}
long long count_swaps( vector<int> S ) {
n = S.size() / 2, s = S;
for( int i = 0 ; i < n * 2 ; i++ ) {
if( s[i] < 0 ) l[abs( s[i] )].emplace_back( i + 1 );
else r[ abs( s[i] )].emplace_back( i + 1 );
}
for( int i = 0 ; i < 100000 ; i++ )
sort( l[i].begin(), l[i].end(), greater<int>() ), sort( r[i].begin(), r[i].end(), greater<int>() );
for( int i = 0 ; i < 100000 ; i++ ) {
for( int j = 0 ; j < l[i].size() ; j++ ) {
//printf("%d %d\n",r[i][j],l[i][j]);
coord.emplace_back( pii( r[i][j], l[i][j] ) );
}
}
sort( coord.begin(), coord.end(), greater<pii>() );
for( int i = 0 ; i < coord.size() ; i++ ) {
int now = n - i - 1;
arr[2*now] = coord[i].y, arr[2*now+1] = coord[i].x;
}
//for( int i = 0 ; i < 2*n ; i++ ) printf("%d ",arr[i]);
//printf("\n");
for( int i = 2*n - 1 ; i >= 0 ; i-- ) {
//cout << query( arr[i] ) << endl;
ans += query( arr[i] ), up( arr[i] );
}
return ans;
}
/*int main()
{
int ne;
vector<int> vec;
scanf("%d",&ne);
for( int i = 0, a ; i < ne ; i++ ) {
scanf("%d",&a);
vec.emplace_back( a );
}
printf("%lld",count_swaps( vec ) );
}*/
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:34:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( int j = 0 ; j < l[i].size() ; j++ ) {
~~^~~~~~~~~~~~~
shoes.cpp:40:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( int i = 0 ; i < coord.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... |