#include<bits/stdc++.h>
using namespace std;
struct player{
int cr, cl;
int bm = -1;
};
int main(){
int n, m, q, pbm;
cin >> n >> m >> q;
vector<player> v(n*2);
auto pos = [n](int x){
return ((x)+2*n)%(2*n);
};
for(int i = 0; i < m; i++){
int x;
cin >> x;
int y = pos(x+n);
v[x].bm=y;
v[y].bm=x;
pbm = x;
}
int cur = pbm;
for(int i = 0; i <= 2*n; i++){
cur = pos(cur+1);
if(v[cur].bm!=-1)pbm = cur;
v[cur].cr=pbm;
}
cur = pbm;
for(int i = 2*n; i >=0 ; i--){
cur = pos(cur-1);
if(v[cur].bm!=-1)pbm = cur;
v[cur].cl=pbm;
}
auto dist = [n, &pos](int x, int y){
return min(pos(x-y), pos(y-x));
};
while(q--){
int x, y;
cin >> x >> y;
int bd = dist(x, y);
bd = min(dist(x, v[x].cl)+dist(v[x].cl+n, y)+1, bd);
bd = min(dist(x, v[x].cr)+dist(v[x].cr+n, y)+1, bd);
cout << bd << '\n';
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:28:18: warning: 'pbm' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | v[cur].cr=pbm;
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
448 KB |
Output is correct |
2 |
Correct |
31 ms |
348 KB |
Output is correct |
3 |
Correct |
35 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
26 ms |
2888 KB |
Output is correct |
6 |
Runtime error |
335 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
331 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
448 KB |
Output is correct |
2 |
Correct |
31 ms |
348 KB |
Output is correct |
3 |
Correct |
35 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
26 ms |
2888 KB |
Output is correct |
6 |
Runtime error |
335 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |