#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000000000000
#define INF2 1000000000000000000
//#define ll long long
///#define cin fin
///#define cout fout
using namespace std;
double const EPS = 1e-14;
///ofstream fout("herding.out");
///ifstream fin("herding.in");
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
long long n, a, b; cin >> n >> a >> b;
pair<long long, long long> p[n];
vector<pair<long long,long long>> v;
long long md;
if(a > INF/b || b > INF/a) md = (INF + 1ll);
else md = (a*b)/__gcd(a,b+1ll);
// cout << n << ' ' << a << ' ' << b << endl;
// cout << md << endl;
bool ok = false;
for(long long i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
//cout << i << endl;
pair<long long, long long> pp;
pp = p[i];
p[i].first %= md;
p[i].second %= md;
if(p[i].second < p[i].first) {
if(pp.second-pp.first+1ll >= md) {
cout << md << endl;
ok = true;
}
v.push_back({p[i].first,0});
v.push_back({md-1ll,1});
v.push_back({0,0});
v.push_back({p[i].second,1});
}
else {
v.push_back({p[i].first,0});
v.push_back({p[i].second,1});
}
}
if(ok) return 0;
sort(v.begin(),v.end()); long long cnt = 0;
long long l = -1, r = 0;
long long ans = 0;
for(int i = 0; i < v.size(); i++) {
if(v[i].second == 0) {
cnt++;
if(l == -1) l = v[i].first;
}
else {
cnt--;
r = max(v[i].first,r);
}
if(cnt == 0) {
ans += r-l+1ll;
l = -1, r = 0;
}
}
cout << ans << endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
1504 KB |
Output is correct |
3 |
Correct |
4 ms |
1504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
500 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1500 KB |
Output is correct |
17 |
Correct |
46 ms |
10424 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
260 ms |
68532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
393 ms |
76708 KB |
Output is correct |
3 |
Correct |
404 ms |
75812 KB |
Output is correct |
4 |
Correct |
371 ms |
77228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
393 ms |
76708 KB |
Output is correct |
3 |
Correct |
404 ms |
75812 KB |
Output is correct |
4 |
Correct |
371 ms |
77228 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
412 ms |
75952 KB |
Output is correct |
7 |
Correct |
410 ms |
75940 KB |
Output is correct |
8 |
Correct |
412 ms |
75944 KB |
Output is correct |
9 |
Correct |
570 ms |
76708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
393 ms |
76708 KB |
Output is correct |
3 |
Correct |
404 ms |
75812 KB |
Output is correct |
4 |
Correct |
371 ms |
77228 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
38 ms |
9928 KB |
Output is correct |
7 |
Correct |
39 ms |
9672 KB |
Output is correct |
8 |
Correct |
37 ms |
10196 KB |
Output is correct |
9 |
Correct |
37 ms |
9680 KB |
Output is correct |
10 |
Correct |
37 ms |
10244 KB |
Output is correct |
11 |
Correct |
41 ms |
9580 KB |
Output is correct |
12 |
Correct |
36 ms |
9680 KB |
Output is correct |
13 |
Correct |
41 ms |
8916 KB |
Output is correct |
14 |
Correct |
37 ms |
10188 KB |
Output is correct |
15 |
Correct |
43 ms |
10788 KB |
Output is correct |
16 |
Correct |
43 ms |
8648 KB |
Output is correct |
17 |
Correct |
39 ms |
10844 KB |
Output is correct |
18 |
Correct |
402 ms |
69820 KB |
Output is correct |
19 |
Correct |
365 ms |
67752 KB |
Output is correct |
20 |
Correct |
473 ms |
68272 KB |
Output is correct |
21 |
Correct |
57 ms |
9680 KB |
Output is correct |
22 |
Correct |
33 ms |
10192 KB |
Output is correct |
23 |
Correct |
104 ms |
29360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
41 ms |
9172 KB |
Output is correct |
3 |
Correct |
42 ms |
9808 KB |
Output is correct |
4 |
Correct |
538 ms |
74660 KB |
Output is correct |
5 |
Correct |
47 ms |
9992 KB |
Output is correct |
6 |
Correct |
41 ms |
10184 KB |
Output is correct |
7 |
Correct |
50 ms |
9052 KB |
Output is correct |
8 |
Correct |
43 ms |
10440 KB |
Output is correct |
9 |
Correct |
40 ms |
9680 KB |
Output is correct |
10 |
Correct |
52 ms |
9252 KB |
Output is correct |
11 |
Correct |
45 ms |
9160 KB |
Output is correct |
12 |
Correct |
42 ms |
9636 KB |
Output is correct |
13 |
Correct |
43 ms |
9568 KB |
Output is correct |
14 |
Correct |
492 ms |
76244 KB |
Output is correct |
15 |
Correct |
45 ms |
10540 KB |
Output is correct |
16 |
Correct |
395 ms |
76636 KB |
Output is correct |
17 |
Correct |
388 ms |
76288 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
1504 KB |
Output is correct |
3 |
Correct |
4 ms |
1504 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
500 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1500 KB |
Output is correct |
17 |
Correct |
46 ms |
10424 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |