#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;
A=A/__gcd(A,B+1);
if (A>2e18/B || A>2e18/B) mod=2e18;
else mod=A*B;
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 |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
704 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 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
212 KB |
Output is correct |
2 |
Correct |
393 ms |
16848 KB |
Output is correct |
3 |
Correct |
413 ms |
16964 KB |
Output is correct |
4 |
Correct |
380 ms |
16812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
393 ms |
16848 KB |
Output is correct |
3 |
Correct |
413 ms |
16964 KB |
Output is correct |
4 |
Correct |
380 ms |
16812 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
386 ms |
16884 KB |
Output is correct |
7 |
Correct |
402 ms |
16832 KB |
Output is correct |
8 |
Correct |
378 ms |
16864 KB |
Output is correct |
9 |
Correct |
408 ms |
16832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
393 ms |
16848 KB |
Output is correct |
3 |
Correct |
413 ms |
16964 KB |
Output is correct |
4 |
Correct |
380 ms |
16812 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
39 ms |
2388 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 |
40 ms |
2412 KB |
Output is correct |
3 |
Correct |
42 ms |
2476 KB |
Output is correct |
4 |
Correct |
442 ms |
16884 KB |
Output is correct |
5 |
Correct |
42 ms |
2504 KB |
Output is correct |
6 |
Correct |
48 ms |
2476 KB |
Output is correct |
7 |
Correct |
39 ms |
2420 KB |
Output is correct |
8 |
Correct |
40 ms |
2440 KB |
Output is correct |
9 |
Correct |
38 ms |
2504 KB |
Output is correct |
10 |
Correct |
39 ms |
2480 KB |
Output is correct |
11 |
Correct |
41 ms |
2512 KB |
Output is correct |
12 |
Correct |
40 ms |
2380 KB |
Output is correct |
13 |
Correct |
40 ms |
2520 KB |
Output is correct |
14 |
Correct |
410 ms |
16752 KB |
Output is correct |
15 |
Correct |
40 ms |
2512 KB |
Output is correct |
16 |
Correct |
402 ms |
16760 KB |
Output is correct |
17 |
Correct |
387 ms |
16796 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
6 ms |
704 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |