#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<ll,ll>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
ll l[1000005],r[1000005];
vii vec;
int main(){
boost;
ll n,A,B;
cin>>n>>A>>B;
for (int i = 0; i < n; ++i){
cin>>l[i]>>r[i];
//if(!(A&1))l[i]*=2LL,r[i]*=2LL;
}
if(A<=2){
cout<<1;return 0;
}
for (int i = 0; i < n; ++i)
{
if((r[i]-l[i]+1)>=A){vec.pb(ii(0,A-1));break;}
if((r[i]%A)<(l[i]%A)){
ll lefty=l[i]%A,righty=A-1;
vec.pb(ii(lefty,righty));
lefty=0,righty=r[i]%A;
vec.pb(ii(lefty,righty));
continue;
}
vec.pb(ii(l[i]%A,r[i]%A));
}
sort(all(vec));
vii final;
ll lefty=vec[0].fi,righty=vec[0].se;
for (int i = 1; i < sz(vec); ++i)
{
if(vec[i].fi<=righty){
righty=max(righty,vec[i].se);
}
else{
final.pb(ii(lefty,righty));
lefty=vec[i].fi,righty=vec[i].se;
}
}
final.pb(ii(lefty,righty));
ll ans=0;
if(A&1)
for(auto it:final)
ans+=(it.se-it.fi+1);
else
for(auto it:final)
ans+=(it.se-it.fi)/2+(((it.se&1)&&(it.fi&1))?0:1);
cout<<ans;
return 0;
}
//long long
//array bounds
//special cases
//binary search
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
8 ms |
908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
653 ms |
56352 KB |
Output is correct |
3 |
Incorrect |
675 ms |
56276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
653 ms |
56352 KB |
Output is correct |
3 |
Incorrect |
675 ms |
56276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
653 ms |
56352 KB |
Output is correct |
3 |
Incorrect |
675 ms |
56276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Incorrect |
50 ms |
1872 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
8 ms |
908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |