Submission #1151529

#TimeUsernameProblemLanguageResultExecution timeMemory
1151529hashimaliCircle Passing (EGOI24_circlepassing)C++20
100 / 100
73 ms8656 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #define endl '\n'
#define ld long double
#define pb push_back
#define pf push_front
#define mod 10000007
#define se second
#define fi first
#define all(ls) (ls).begin(),(ls).end()
#define int long long
using namespace std;
using namespace __gnu_pbds;
template<typename type>using ordered_set=tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename type>using ordered_multiset=tree<type,null_type,less_equal<type>,rb_tree_tag,tree_order_statistics_node_update>;
void solve(){
    int n,m,q;
    cin>>n>>m>>q;
    vector<int>ls;
    for(int i=0;i<m;i++){
        int e;
        cin>>e;
        ls.pb(e);
    }
    for(int i=0;i<m;i++)
        ls.pb(ls[i]+n);
    sort(all(ls));
    while(q--){
        int x,y;
        cin>>x>>y;
        int lb=lower_bound(all(ls),x)-ls.begin();
        int a=lb-1,b=lb;
        if(a<0 or a>=ls.size())
            a=ls.size()-1;
        if(b<0 or b>=ls.size())
            b=0;
        int ans=min(abs(x-y),2*n-abs(x-y));
        int left=min(abs(x-ls[a]),2*n-abs(x-ls[a]));
        int right=min(abs(((ls[a]+n)%(2*n))-y),2*n-abs(((ls[a]+n)%(2*n))-y))+1;
        ans=min(ans,left+right);
        left=min(abs(x-ls[b]),2*n-abs(x-ls[b]));
        right=min(abs(((ls[b]+n)%(2*n))-y),2*n-abs(((ls[b]+n)%(2*n))-y))+1;
        ans=min(ans,left+right);
        cout<<ans<<endl;
    }
}  
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    for(int i=1;i<=t;i++){
        // cout<<"Scenario #"<<i<<":"<<" ";
        solve();
    }
}
#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...