#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define endl '\n'
#define eb emplace_back
#define em emplace
#define pb push_back
#define pf push_front
#define pp pop_back
#define fr first
#define sc second
#define sz size
#define ir insert
using namespace std;
const ll md =1e9 + 7;
const ll mx = 1e9 ;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie() ;
ll n , m , q ,a , b ;
cin >> n >> m >> q ;
set<ll>s ;
while(m--) {
cin >> a ;
s.ir(a - n) ;
s.ir(a - 2 * n) ;
s.ir(a) ;
s.ir(a + n) ;
s.ir(a + 2 * b) ;
s.ir(a + 3 *n) ;
}
while(q--) {
cin >>a >> b;
if(a >b) b += 2 * n ;
ll ans = min(b - a , a - b + 2 * n) ;
auto it = s.lower_bound(a) ;
ans = min(ans ,abs(*it + n - b) + abs(*it - a) + 1) ;
it-- ;
ans = min(ans, abs(*it + n-b) + abs(*it - a) + 1) ;
cout << ans << endl ;
}
return 0;
}
# | 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... |