#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define pb push_back
using lint=__int128_t;
const int lim=200100;
const int mod=1e9+7;
using pii=pair<int,int>;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen(".in","r",stdin);freopen(".out","w",stdout);
#endif
int n,a,b;
cin>>n>>a>>b;
lint cntofdif;
if((b+1)%a==0){
cntofdif=b;
}else{
cntofdif=a;
cntofdif*=b;
cntofdif=min<lint>(cntofdif,mod*mod);
}
int all=cntofdif;
//cerr<<all<<"\n";
vector<pii>ranges;
for(int i=0;i<n;i++){
int l,r;
cin>>l>>r;
if(all<=r-l+1){
cout<<all;
return 0;
}
l%=all;
r%=all;
if(l<=r){
ranges.pb({l,r});
//cerr<<"inserted "<<l<<" "<<r<<"\n";
}
else{
//cerr<<"oops "<<l<<" "<<r<<"\n";
ranges.pb({l,all-1});
ranges.pb({0,r});
}
}
sort(ranges.begin(),ranges.end());
int cnt=0,left=-1;
for(auto[f,s]:ranges){
if(left<f){
cnt+=s-f+1;
}else{
cnt+=s-left;
}
//cerr<<f<<" "<<s<<" "<<cnt<<"\n";
left=max(left,s);
}
cout<<cnt<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
2 ms |
736 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
219 ms |
16856 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
219 ms |
16856 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
219 ms |
16856 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
29 ms |
2540 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
2 ms |
736 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |