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;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
int main() {
ll n, a, b; cin >> n >> a >> b;
map<ll, ll> mp;
while(n--){
ll l, r; cin >> l >> r;
l%=a*b;
r%=a*b;
if(l>r){
mp[l]++;
mp[a*b]--;
mp[0]++;
mp[r+1]--;
}
else{
mp[l]++;
mp[r+1]--;
}
} // 1 0 1 -1 -1 0 1 0 -1
// 1 1 2 1 0 1 1 0
ll cnt=0, nw=0, ans=0, bul=0;
for(auto& u : mp){
cnt+=u.S;
// cout << "[" << u.first << ',' << u.second << ']' << cnt << endl;
if(!cnt){
ans+=u.F-nw;
// cout << ans << endl;
bul=0;
} else{
if(!bul){
nw=u.F;
bul=1;
}
}
}
cout << ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |