forked from abeaumont/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.cc
More file actions
27 lines (26 loc) · 576 Bytes
/
a.cc
File metadata and controls
27 lines (26 loc) · 576 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// https://codeforces.com/contest/1020/problem/A
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n,h,a,b,k,ta,tb,fa,fb;
cin>>n>>h>>a>>b>>k;
for(int i=0;i<k;i++){
cin>>ta>>fa>>tb>>fb;
if(ta==tb){
cout<<llabs(fa-fb)<<endl;
continue;
}
ll c=llabs(tb-ta),s=0,t=0;
if(fa>=a&&fa<=b)s=fa;
else if(fa<a){s=a;c+=a-fa;}
else{s=b;c+=fa-b;}
if(fb>=a&&fb<=b)t=fb;
else if(fb<a){t=a;c+=a-fb;}
else{t=b;c+=fb-b;}
c+=llabs(t-s);
cout<<c<<endl;
}
}