#include <bits/stdc++.h>
using namespace std;
# define int long long
# define fir first
# define sec second
# define pb push_back
const int cnst = 2e5+5;
bool mutipletestcase = 0;
//bool debug = false;
int gcd(int a, int b) {return b ? gcd(b, a%b): a;}
int lcm(int a, int b) {return a/gcd(a, b+1)*b;}
void solve() {
int n, a, b; cin >> n >> a >> b;
pair<int, int> num[n+5];
for(int i = 1; i<=n; i++) {
int x, y; cin >> x >> y;
num[i] = {x, y};
}
int val = lcm(a, b);
int ans = 0;
int get[val*2+5];
memset(get, 0, sizeof(get));
for(int i = 1; i<=n; i++) {
int x, y; x = num[i].fir, y = num[i].sec;
int len = y-x+1;
if(len >= val) ans = val;
x %= val;
y %= val;
if(!y) y += val;
if(!x) x += val;
if(y < x) y += val;
// cerr << x << " " << y << endl;
get[x]+=1, get[y+1] -= 1;
}
if(ans == val) cout << ans << endl;
else {
bool yes[val+5];
memset(yes, 0, sizeof(yes));
for(int i = 1; i<=2*val; i++) {
get[i] += get[i-1];
// cerr << i << " " << get[i] << " " << endl;
// if(get[i]) cerr << i << " ";
if(get[i]) yes[i%val] = 1;
}
for(int i = 0; i<=val; i++) {
if(yes[i]) ans++;
}
cout << ans << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
int t = 1;
if(mutipletestcase) cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
81 ms |
107908 KB |
Output is correct |
3 |
Correct |
62 ms |
82928 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
2260 KB |
Output is correct |
16 |
Correct |
5 ms |
3540 KB |
Output is correct |
17 |
Correct |
49 ms |
34636 KB |
Output is correct |
18 |
Runtime error |
182 ms |
524288 KB |
Execution killed with signal 9 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
166 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
14 ms |
16340 KB |
Output is correct |
3 |
Correct |
15 ms |
16532 KB |
Output is correct |
4 |
Correct |
11 ms |
13824 KB |
Output is correct |
5 |
Correct |
209 ms |
32564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
275 ms |
36564 KB |
Output is correct |
3 |
Runtime error |
383 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
275 ms |
36564 KB |
Output is correct |
3 |
Runtime error |
383 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
275 ms |
36564 KB |
Output is correct |
3 |
Runtime error |
383 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
184 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
81 ms |
107908 KB |
Output is correct |
3 |
Correct |
62 ms |
82928 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
2 ms |
2260 KB |
Output is correct |
16 |
Correct |
5 ms |
3540 KB |
Output is correct |
17 |
Correct |
49 ms |
34636 KB |
Output is correct |
18 |
Runtime error |
182 ms |
524288 KB |
Execution killed with signal 9 |
19 |
Halted |
0 ms |
0 KB |
- |