# include <bits/stdc++.h>
# define int long long
# define vi vector<int>
# define pb push_back
# define pii pair<int, int>
# define fi first
# define se second
# define endl '\n'
# define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, a, b;
void solve() {
cin >> n >> a >> b;
__int128_t t=a*b;
int cycle=t / __gcd(a, b+1);
vector<pii> v;
for(int i=1; i<=n; i++) {
int l, r;
cin >> l >> r;
l%=cycle;
r%=cycle;
if(r < l) {
v.pb({l, cycle-1});
v.pb({0, r});
} else {
v.pb({l, r});
}
}
sort(v.begin(), v.end());
bool st=1;
int l=0, r=1, ans=0;
// for(pii i : v) cout << "l r " << i.fi << " " << i.se << endl;
for(auto i : v) {
if(st) {
l=i.fi, r=i.se;
st=0;
continue;
}
if(i.fi>=l && i.fi<=r) {
r=max(r, i.se);
} else {
ans+=(r-l+1);
l=i.fi, r=i.se;
}
}
ans+=(r-l+1);
cout << ans << endl;
}
signed main() {
jess;
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
984 KB |
Output is correct |
3 |
Correct |
4 ms |
1056 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
320 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
984 KB |
Output is correct |
17 |
Correct |
36 ms |
3460 KB |
Output is correct |
18 |
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 |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
211 ms |
16928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
342 ms |
16900 KB |
Output is correct |
3 |
Correct |
313 ms |
17708 KB |
Output is correct |
4 |
Correct |
330 ms |
17576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
342 ms |
16900 KB |
Output is correct |
3 |
Correct |
313 ms |
17708 KB |
Output is correct |
4 |
Correct |
330 ms |
17576 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
352 ms |
17772 KB |
Output is correct |
7 |
Correct |
321 ms |
17820 KB |
Output is correct |
8 |
Correct |
322 ms |
17372 KB |
Output is correct |
9 |
Correct |
344 ms |
17580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
342 ms |
16900 KB |
Output is correct |
3 |
Correct |
313 ms |
17708 KB |
Output is correct |
4 |
Correct |
330 ms |
17576 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
31 ms |
3116 KB |
Output is correct |
7 |
Correct |
39 ms |
3040 KB |
Output is correct |
8 |
Correct |
32 ms |
3068 KB |
Output is correct |
9 |
Correct |
35 ms |
2956 KB |
Output is correct |
10 |
Correct |
33 ms |
3264 KB |
Output is correct |
11 |
Correct |
40 ms |
2968 KB |
Output is correct |
12 |
Correct |
34 ms |
3020 KB |
Output is correct |
13 |
Correct |
34 ms |
2920 KB |
Output is correct |
14 |
Correct |
32 ms |
3120 KB |
Output is correct |
15 |
Correct |
38 ms |
3020 KB |
Output is correct |
16 |
Correct |
36 ms |
3156 KB |
Output is correct |
17 |
Correct |
33 ms |
3048 KB |
Output is correct |
18 |
Correct |
325 ms |
17588 KB |
Output is correct |
19 |
Correct |
306 ms |
17316 KB |
Output is correct |
20 |
Correct |
340 ms |
18036 KB |
Output is correct |
21 |
Correct |
38 ms |
3140 KB |
Output is correct |
22 |
Correct |
31 ms |
3068 KB |
Output is correct |
23 |
Correct |
97 ms |
9924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
38 ms |
3240 KB |
Output is correct |
3 |
Correct |
35 ms |
2948 KB |
Output is correct |
4 |
Correct |
361 ms |
17692 KB |
Output is correct |
5 |
Correct |
35 ms |
3140 KB |
Output is correct |
6 |
Correct |
36 ms |
3056 KB |
Output is correct |
7 |
Correct |
37 ms |
3204 KB |
Output is correct |
8 |
Correct |
36 ms |
3136 KB |
Output is correct |
9 |
Correct |
34 ms |
2980 KB |
Output is correct |
10 |
Correct |
39 ms |
3040 KB |
Output is correct |
11 |
Correct |
35 ms |
3096 KB |
Output is correct |
12 |
Correct |
36 ms |
3032 KB |
Output is correct |
13 |
Correct |
39 ms |
3148 KB |
Output is correct |
14 |
Correct |
320 ms |
17496 KB |
Output is correct |
15 |
Correct |
33 ms |
3048 KB |
Output is correct |
16 |
Correct |
333 ms |
17348 KB |
Output is correct |
17 |
Correct |
337 ms |
18128 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
984 KB |
Output is correct |
3 |
Correct |
4 ms |
1056 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
320 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
984 KB |
Output is correct |
17 |
Correct |
36 ms |
3460 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |