이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,t,n,x,y,m,q;
set<long long>s;
long long dist(long long d,long long e){
d=d%(2*n);
e=e%(2*n);
//cout<<d<<" "<<e<<" ";
return min(abs(d-e),abs(2*n-abs(e-d)));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m>>q;
for(long long i=0;i<m;i++){
cin>>a;
s.insert(a);
s.insert(a+n);
}
for(long long i=0;i<q;i++){
// cout<<s.size()<<" ";
cin>>x>>y;
long long pom1,pom2;
if(s.lower_bound(x)!=s.end() && s.lower_bound(x)!=s.begin()){//x,x-1
pom1=*s.lower_bound(x);
if(pom1==x)
pom2=x;
else
pom2=*--s.lower_bound(x);
//cout<<x;
}
else{
pom1=*s.begin();
if(pom1==x)
pom2=x;
else
pom2=*--s.end();
}
cout<<min(min(dist(x,y),1+dist(pom1+n,y)+dist(x,pom1)),1+dist(pom2+n,y)+dist(x,pom2))<<"\n";
//cout<<pom1<<" "<<pom2<<"\n";
}
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... |