Submission #1058143

#TimeUsernameProblemLanguageResultExecution timeMemory
1058143user736482Circle Passing (EGOI24_circlepassing)C++17
100 / 100
208 ms47576 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...