This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = (int)1e6+10;
int n, m, q;
int k[mxN];
int dis(int a, int b){ return min(abs(a-b), n*2-abs(a-b)); }
int getDis(int a, int K, int b){
return min(dis(a,K)+1+dis(K+n,b), dis(a,K+n)+1+dis(K,b));
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> q;
for(int i = 0; i < m; i++) cin >> k[i];
while(q--){
int a, b; cin >> a >> b;
if(a>b) swap(a,b);
int ans = dis(a,b);
int pos = lower_bound(k,k+m,a)-k;
int tot = min(m, (int)1e4/2); int tot2 = tot;
if(pos==m) pos=0;
ans = min(ans, getDis(a,k[pos],b));
if(pos==0) pos=m-1;
else pos--;
ans = min(ans, getDis(a,k[pos],b));
cout << ans << "\n";
}
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:22:43: warning: unused variable 'tot2' [-Wunused-variable]
22 | int tot = min(m, (int)1e4/2); int tot2 = tot;
| ^~~~
# | 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... |