#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll n,A,B,mod,ans;
vector<pll> v;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>A>>B;
mod=(A*B)/__gcd(A,B+1);
while (n--) {
ll l,r;
cin>>l>>r;
if (r-l+1>=mod) {
cout<<mod;
return 0;
}
l%=mod;
r%=mod;
if (l<=r) v.push_back(pll(l,r));
else v.push_back(pll(l,mod-1)), v.push_back(pll(0,r));
}
sort(v.begin(),v.end());
ll mmax=-1;
for (auto s : v) {
if (mmax<s.first) {
ans+=(s.second-s.first+1);
mmax=s.second;
} else if (s.first<mmax && mmax<s.second) {
ans+=(s.second-mmax);
mmax=s.second;
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
4 ms |
980 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
244 KB |
Output is correct |
2 |
Correct |
379 ms |
17328 KB |
Output is correct |
3 |
Correct |
391 ms |
17636 KB |
Output is correct |
4 |
Correct |
360 ms |
17644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
244 KB |
Output is correct |
2 |
Correct |
379 ms |
17328 KB |
Output is correct |
3 |
Correct |
391 ms |
17636 KB |
Output is correct |
4 |
Correct |
360 ms |
17644 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
370 ms |
17644 KB |
Output is correct |
7 |
Correct |
416 ms |
17608 KB |
Output is correct |
8 |
Correct |
423 ms |
17860 KB |
Output is correct |
9 |
Correct |
398 ms |
17576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
244 KB |
Output is correct |
2 |
Correct |
379 ms |
17328 KB |
Output is correct |
3 |
Correct |
391 ms |
17636 KB |
Output is correct |
4 |
Correct |
360 ms |
17644 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
40 ms |
5632 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
44 ms |
5580 KB |
Output is correct |
3 |
Correct |
52 ms |
5644 KB |
Output is correct |
4 |
Correct |
449 ms |
17576 KB |
Output is correct |
5 |
Correct |
42 ms |
5720 KB |
Output is correct |
6 |
Correct |
41 ms |
5696 KB |
Output is correct |
7 |
Correct |
45 ms |
5696 KB |
Output is correct |
8 |
Correct |
46 ms |
5676 KB |
Output is correct |
9 |
Correct |
45 ms |
5628 KB |
Output is correct |
10 |
Correct |
42 ms |
5636 KB |
Output is correct |
11 |
Correct |
42 ms |
5732 KB |
Output is correct |
12 |
Correct |
38 ms |
5692 KB |
Output is correct |
13 |
Correct |
50 ms |
5632 KB |
Output is correct |
14 |
Correct |
415 ms |
17548 KB |
Output is correct |
15 |
Correct |
43 ms |
5724 KB |
Output is correct |
16 |
Correct |
395 ms |
53368 KB |
Output is correct |
17 |
Correct |
419 ms |
53220 KB |
Output is correct |
18 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
4 ms |
980 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |