#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef pair <int,int> pii;
int N, M, Q;
vector <int> bff;
int dist ( int a, int b ) {
return min ( abs(b-a), 2*N-abs(b-a) );
}
bool check_bff ( int a, int b ) {
auto pnt_a = lower_bound ( bff.begin(), bff.end(), a ),
pnt_b = upper_bound ( bff.begin(), bff.end(), b );
if ( a <= b )
return pnt_b - pnt_a > 0;
return pnt_a != bff.end() or pnt_b != bff.begin();
}
int get_ans ( int x_i, int y_i ) {
int d_x = dist ( x_i, y_i ), bff_x = (x_i+N)%(2*N);
int res = d_x;
if ( check_bff ( y_i, bff_x ) )
res = min ( res, dist ( y_i, bff_x ) + 1 );
return res;
}
int main () {
#ifndef LOCAL
#endif
scanf ( "%d%d%d", &N, &M, &Q );
while ( M-- ) {
int curr_bff;
scanf ( "%d", &curr_bff );
bff.pb ( curr_bff ), bff.pb ( curr_bff + N );
}
sort ( bff.begin(), bff.end() );
printf ( "%d\n", dist ( 1, 8 ) );
while ( Q-- ) {
int x_i, y_i;
scanf ( "%d%d", &x_i, &y_i );
printf ( "%d\n", get_ans ( x_i, y_i ) );
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:39:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf ( "%d%d%d", &N, &M, &Q );
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:42:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf ( "%d", &curr_bff );
| ~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:51:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf ( "%d%d", &x_i, &y_i );
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |