제출 #127962

#제출 시각아이디문제언어결과실행 시간메모리
127962DodgeBallMan정렬하기 (IOI15_sorting)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "sorting.h" #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 2e5 + 10; const int M = 6e5 + 10; int n, m, s[N], x[M], y[M]; vector<pii> chk( int mid ) { int pos[N], te[N]; vector<pii> ret; for( int i = 0 ; i <= n ; i++ ) te[i] = s[i]; for( int i = 0 ; i <= mid ; i++ ) swap( te[x[i]], te[y[i]] ); for( int i = 0 ; i < n ; i++ ) pos[te[i]] = i; for( int i = 0 ; i < n ; i++ ) if( te[i] != i ) { ret.emplace_back( pii( te[i], i ) ); int now = te[i]; swap( te[i], te[pos[i]] ); swap( pos[now], pos[i] ); } return ret; } int findSwapPairs( int N, int S[], int M, int X[], int Y[], int P[], int Q[] ) { int pos[N]; n = N, m = M; for( int i = 0 ; i < n ; i++ ) s[i] = S[i]; for( int i = 0 ; i < m ; i++ ) x[i] = X[i], y[i] = Y[i]; int l = 0, r = m; while( l < r ) { int mid = ( l + r ) >> 1; if( chk( mid ).size() <= mid ) r = mid; else l = mid + 1; } vector<pii> ans = chk( l ); for( int i = 0 ; i < n ; i++ ) pos[s[i]] = i; for( int i = 0 ; i < r ; i++ ) { swap( pos[s[x[i]]], pos[s[y[i]]] ); swap( s[x[i]], s[y[i]] ); if( i < ans.size() ) { int a = ans[i].x, b = ans[i].y; p[i] = pos[a], q[i] = pos[b]; swap( s[pos[a]], s[pos[b]] ); swap( pos[a], pos[b] ); } } for( int i = ans.size() ; i < r ; i++ ) p[i] = 0, q[i] = 0; return l; }

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

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:29:78: warning: declaration of 'M' shadows a global declaration [-Wshadow]
 int findSwapPairs( int N, int S[], int M, int X[], int Y[], int P[], int Q[] ) {
                                                                              ^
sorting.cpp:10:11: note: shadowed declaration is here
 const int M = 6e5 + 10;
           ^
sorting.cpp:29:78: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int findSwapPairs( int N, int S[], int M, int X[], int Y[], int P[], int Q[] ) {
                                                                              ^
sorting.cpp:9:11: note: shadowed declaration is here
 const int N = 2e5 + 10;
           ^
sorting.cpp:37:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if( chk( mid ).size() <= mid ) r = mid;
             ~~~~~~~~~~~~~~~~~~^~~~~~
sorting.cpp:45:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if( i < ans.size() ) {
             ~~^~~~~~~~~~~~
sorting.cpp:47:13: error: 'p' was not declared in this scope
             p[i] = pos[a], q[i] = pos[b];
             ^
sorting.cpp:47:28: error: 'q' was not declared in this scope
             p[i] = pos[a], q[i] = pos[b];
                            ^
sorting.cpp:52:26: warning: conversion to 'int' from 'std::vector<std::pair<int, int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     for( int i = ans.size() ; i < r ; i++ ) p[i] = 0, q[i] = 0;
                  ~~~~~~~~^~
sorting.cpp:52:45: error: 'p' was not declared in this scope
     for( int i = ans.size() ; i < r ; i++ ) p[i] = 0, q[i] = 0;
                                             ^
sorting.cpp:52:55: error: 'q' was not declared in this scope
     for( int i = ans.size() ; i < r ; i++ ) p[i] = 0, q[i] = 0;
                                                       ^
sorting.cpp:29:67: warning: unused parameter 'P' [-Wunused-parameter]
 int findSwapPairs( int N, int S[], int M, int X[], int Y[], int P[], int Q[] ) {
                                                                   ^
sorting.cpp:29:76: warning: unused parameter 'Q' [-Wunused-parameter]
 int findSwapPairs( int N, int S[], int M, int X[], int Y[], int P[], int Q[] ) {
                                                                            ^