#define DEBUG
// #define FASTIO
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#define F first
#define S second
#define pb push_back
#define endl "\n"
#ifdef FASTIO
#define pr(x) printf("%d", x)
#define ps printf(" ")
#define endc printf("\n")
#define pl(x) printf("%lld", x)
#define pf(x) printf("%lf", x)
#define sc(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define sf(x) scanf("%lf", &x)
#define IOS
#endif
#ifndef FASTIO
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); }
#endif
#ifdef DEBUG
#define dbg(s) {s;}
#endif
#ifndef DEBUG
#define dbg(s)
#endif
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { // from [0, n-1]
return uniform_int_distribution<int>(0, x - 1)(rng);
}
#define int ll
#define i32 int32_t
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
inline string ps(pii z) {
stringstream ss; ss << "[" << z.F << ", " << z.S << "]";
return ss.str();
}
ll gcd(ll x, ll y) {
if (x < y) return gcd(y, x);
if (y == 0) return x;
return gcd(y, x % y);
}
const ll mod = 1e9 + 7;
ll modexp(ll x, ll ex) {
ll ans = 1ll;
while (ex > 0) {
if (ex & 1ll) ans = (ans * x) % mod;
ex >>= 1ll;
x = (x * x) % mod;
}
return ans;
}
const int maxn = 1e6 + 7;
const ll inf = 1e18 + 7;
vector < pii > v;
i32 main() {
//freopen("<file>.in", "r", stdin);
//freopen("<file>.out", "w", stdout);
IOS;
int n, A, B; cin >> n >> A >> B;
int g = gcd(A, B + 1); A /= g;
if (A >= inf / B) A = inf;
else A *= B;
for (int j = 1; j <= n; j++) {
int l, r; cin >> l >> r;
if (r - l >= A) {
cout << A << endl; return 0;
}
if (l <= A * (r / A)) {
v.pb({0, r % A});
if (l < A * (r / A))
v.pb({l % A, A - 1});
} else {
v.pb({l % A, r % A});
}
}
sort(all(v));
int ans = 0;
for (int j = 0; j < v.size(); ) {
int i = j; pii ci = v[j];
while (i + 1 < v.size() && v[i + 1].F <= ci.S) {
i++; ci.S = max(ci.S, v[i].S);
}
j = i + 1;
ans += ci.S - ci.F + 1;
}
cout << ans << endl;
}
Compilation message
strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:137:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < v.size(); ) {
~~^~~~~~~~~~
strange_device.cpp:139:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i + 1 < v.size() && v[i + 1].F <= ci.S) {
~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
1016 KB |
Output is correct |
3 |
Correct |
9 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
0 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
9 ms |
1036 KB |
Output is correct |
17 |
Correct |
69 ms |
3312 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
449 ms |
17736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
610 ms |
19008 KB |
Output is correct |
3 |
Correct |
604 ms |
17720 KB |
Output is correct |
4 |
Correct |
603 ms |
17696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
610 ms |
19008 KB |
Output is correct |
3 |
Correct |
604 ms |
17720 KB |
Output is correct |
4 |
Correct |
603 ms |
17696 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
608 ms |
17700 KB |
Output is correct |
7 |
Correct |
625 ms |
17628 KB |
Output is correct |
8 |
Correct |
626 ms |
17556 KB |
Output is correct |
9 |
Correct |
667 ms |
17480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
610 ms |
19008 KB |
Output is correct |
3 |
Correct |
604 ms |
17720 KB |
Output is correct |
4 |
Correct |
603 ms |
17696 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
61 ms |
3052 KB |
Output is correct |
7 |
Correct |
66 ms |
3104 KB |
Output is correct |
8 |
Correct |
61 ms |
3184 KB |
Output is correct |
9 |
Correct |
64 ms |
3156 KB |
Output is correct |
10 |
Correct |
61 ms |
3300 KB |
Output is correct |
11 |
Correct |
65 ms |
3200 KB |
Output is correct |
12 |
Correct |
61 ms |
3180 KB |
Output is correct |
13 |
Correct |
68 ms |
3224 KB |
Output is correct |
14 |
Correct |
61 ms |
3180 KB |
Output is correct |
15 |
Correct |
67 ms |
3152 KB |
Output is correct |
16 |
Correct |
68 ms |
3312 KB |
Output is correct |
17 |
Correct |
64 ms |
3304 KB |
Output is correct |
18 |
Correct |
614 ms |
17400 KB |
Output is correct |
19 |
Correct |
719 ms |
17416 KB |
Output is correct |
20 |
Correct |
673 ms |
17488 KB |
Output is correct |
21 |
Correct |
68 ms |
3508 KB |
Output is correct |
22 |
Correct |
61 ms |
3052 KB |
Output is correct |
23 |
Correct |
195 ms |
10852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
67 ms |
3464 KB |
Output is correct |
3 |
Correct |
68 ms |
3080 KB |
Output is correct |
4 |
Correct |
686 ms |
17252 KB |
Output is correct |
5 |
Correct |
67 ms |
2924 KB |
Output is correct |
6 |
Correct |
67 ms |
2928 KB |
Output is correct |
7 |
Correct |
67 ms |
2928 KB |
Output is correct |
8 |
Correct |
69 ms |
2932 KB |
Output is correct |
9 |
Correct |
65 ms |
2920 KB |
Output is correct |
10 |
Correct |
67 ms |
2928 KB |
Output is correct |
11 |
Correct |
68 ms |
2924 KB |
Output is correct |
12 |
Correct |
60 ms |
2924 KB |
Output is correct |
13 |
Correct |
69 ms |
2972 KB |
Output is correct |
14 |
Correct |
681 ms |
17340 KB |
Output is correct |
15 |
Correct |
67 ms |
3308 KB |
Output is correct |
16 |
Correct |
618 ms |
17480 KB |
Output is correct |
17 |
Correct |
607 ms |
17376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
1016 KB |
Output is correct |
3 |
Correct |
9 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
0 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
9 ms |
1036 KB |
Output is correct |
17 |
Correct |
69 ms |
3312 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
449 ms |
17736 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
610 ms |
19008 KB |
Output is correct |
31 |
Correct |
604 ms |
17720 KB |
Output is correct |
32 |
Correct |
603 ms |
17696 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
608 ms |
17700 KB |
Output is correct |
35 |
Correct |
625 ms |
17628 KB |
Output is correct |
36 |
Correct |
626 ms |
17556 KB |
Output is correct |
37 |
Correct |
667 ms |
17480 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
61 ms |
3052 KB |
Output is correct |
40 |
Correct |
66 ms |
3104 KB |
Output is correct |
41 |
Correct |
61 ms |
3184 KB |
Output is correct |
42 |
Correct |
64 ms |
3156 KB |
Output is correct |
43 |
Correct |
61 ms |
3300 KB |
Output is correct |
44 |
Correct |
65 ms |
3200 KB |
Output is correct |
45 |
Correct |
61 ms |
3180 KB |
Output is correct |
46 |
Correct |
68 ms |
3224 KB |
Output is correct |
47 |
Correct |
61 ms |
3180 KB |
Output is correct |
48 |
Correct |
67 ms |
3152 KB |
Output is correct |
49 |
Correct |
68 ms |
3312 KB |
Output is correct |
50 |
Correct |
64 ms |
3304 KB |
Output is correct |
51 |
Correct |
614 ms |
17400 KB |
Output is correct |
52 |
Correct |
719 ms |
17416 KB |
Output is correct |
53 |
Correct |
673 ms |
17488 KB |
Output is correct |
54 |
Correct |
68 ms |
3508 KB |
Output is correct |
55 |
Correct |
61 ms |
3052 KB |
Output is correct |
56 |
Correct |
195 ms |
10852 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
67 ms |
3464 KB |
Output is correct |
59 |
Correct |
68 ms |
3080 KB |
Output is correct |
60 |
Correct |
686 ms |
17252 KB |
Output is correct |
61 |
Correct |
67 ms |
2924 KB |
Output is correct |
62 |
Correct |
67 ms |
2928 KB |
Output is correct |
63 |
Correct |
67 ms |
2928 KB |
Output is correct |
64 |
Correct |
69 ms |
2932 KB |
Output is correct |
65 |
Correct |
65 ms |
2920 KB |
Output is correct |
66 |
Correct |
67 ms |
2928 KB |
Output is correct |
67 |
Correct |
68 ms |
2924 KB |
Output is correct |
68 |
Correct |
60 ms |
2924 KB |
Output is correct |
69 |
Correct |
69 ms |
2972 KB |
Output is correct |
70 |
Correct |
681 ms |
17340 KB |
Output is correct |
71 |
Correct |
67 ms |
3308 KB |
Output is correct |
72 |
Correct |
618 ms |
17480 KB |
Output is correct |
73 |
Correct |
607 ms |
17376 KB |
Output is correct |
74 |
Correct |
2 ms |
376 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
2 ms |
376 KB |
Output is correct |
77 |
Correct |
2 ms |
376 KB |
Output is correct |
78 |
Correct |
2 ms |
376 KB |
Output is correct |
79 |
Correct |
8 ms |
1144 KB |
Output is correct |
80 |
Correct |
705 ms |
17564 KB |
Output is correct |
81 |
Correct |
747 ms |
17488 KB |
Output is correct |
82 |
Correct |
652 ms |
17488 KB |
Output is correct |
83 |
Correct |
672 ms |
17400 KB |
Output is correct |
84 |
Correct |
676 ms |
17596 KB |
Output is correct |
85 |
Correct |
663 ms |
17484 KB |
Output is correct |
86 |
Correct |
192 ms |
9500 KB |
Output is correct |
87 |
Correct |
2 ms |
348 KB |
Output is correct |