//1610612741, 1000000007
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123
const int N = 1e6 + 7;
const int INF = 1e9 + 7;
int n;
ll A, B, p, ans;
ll bound = 1e18;
bool trigger = false;
vector < pair < ll, ll > > s;
main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> A >> B;
p = A / __gcd(B + 1, A);
if (B > bound / p)
p = bound;
else
p *= B;
for (int i = 1; i <= n; i++){
ll l, r;
cin >> l >> r;
if (r - l + 1 >= p)
trigger = true;
l %= p;
r %= p;
if (l > r){
s.pb({l, p - 1});
s.pb({0, r});
}
else
s.pb({l, r});
}
if (trigger){
cout << p;
return 0;
}
sort(all(s));
ll r = -1;
for (auto it : s){
if (r < it.fr)
r = it.fr - 1;
ans += max(0LL, it.sc - r);
r = max(r, it.sc);
}
cout << ans << endl;
}
Compilation message
strange_device.cpp:4: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
4 | #pragma GCC optimization ("unroll-loops")
|
strange_device.cpp:34:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
34 | main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
59 ms |
3228 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
425 ms |
17600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
468 ms |
17872 KB |
Output is correct |
3 |
Correct |
530 ms |
17876 KB |
Output is correct |
4 |
Correct |
539 ms |
18004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
468 ms |
17872 KB |
Output is correct |
3 |
Correct |
530 ms |
17876 KB |
Output is correct |
4 |
Correct |
539 ms |
18004 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
543 ms |
17956 KB |
Output is correct |
7 |
Correct |
475 ms |
17876 KB |
Output is correct |
8 |
Correct |
513 ms |
17940 KB |
Output is correct |
9 |
Correct |
501 ms |
17876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
468 ms |
17872 KB |
Output is correct |
3 |
Correct |
530 ms |
17876 KB |
Output is correct |
4 |
Correct |
539 ms |
18004 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
52 ms |
3184 KB |
Output is correct |
7 |
Correct |
61 ms |
3196 KB |
Output is correct |
8 |
Correct |
49 ms |
3184 KB |
Output is correct |
9 |
Correct |
46 ms |
3184 KB |
Output is correct |
10 |
Correct |
47 ms |
3184 KB |
Output is correct |
11 |
Correct |
46 ms |
3188 KB |
Output is correct |
12 |
Correct |
58 ms |
3192 KB |
Output is correct |
13 |
Correct |
51 ms |
3184 KB |
Output is correct |
14 |
Correct |
45 ms |
3192 KB |
Output is correct |
15 |
Correct |
49 ms |
3184 KB |
Output is correct |
16 |
Correct |
48 ms |
3192 KB |
Output is correct |
17 |
Correct |
58 ms |
3064 KB |
Output is correct |
18 |
Correct |
496 ms |
17364 KB |
Output is correct |
19 |
Correct |
462 ms |
17912 KB |
Output is correct |
20 |
Correct |
520 ms |
17620 KB |
Output is correct |
21 |
Correct |
55 ms |
2928 KB |
Output is correct |
22 |
Correct |
43 ms |
2928 KB |
Output is correct |
23 |
Correct |
164 ms |
8928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
50 ms |
2936 KB |
Output is correct |
3 |
Correct |
48 ms |
2924 KB |
Output is correct |
4 |
Correct |
522 ms |
17284 KB |
Output is correct |
5 |
Correct |
48 ms |
3064 KB |
Output is correct |
6 |
Correct |
46 ms |
2928 KB |
Output is correct |
7 |
Correct |
46 ms |
2932 KB |
Output is correct |
8 |
Correct |
48 ms |
2936 KB |
Output is correct |
9 |
Correct |
49 ms |
2936 KB |
Output is correct |
10 |
Correct |
49 ms |
2928 KB |
Output is correct |
11 |
Correct |
47 ms |
2936 KB |
Output is correct |
12 |
Correct |
45 ms |
2928 KB |
Output is correct |
13 |
Correct |
58 ms |
2928 KB |
Output is correct |
14 |
Correct |
505 ms |
17236 KB |
Output is correct |
15 |
Correct |
49 ms |
2928 KB |
Output is correct |
16 |
Correct |
459 ms |
17492 KB |
Output is correct |
17 |
Correct |
455 ms |
17492 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
1152 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
59 ms |
3228 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
425 ms |
17600 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
468 ms |
17872 KB |
Output is correct |
31 |
Correct |
530 ms |
17876 KB |
Output is correct |
32 |
Correct |
539 ms |
18004 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
543 ms |
17956 KB |
Output is correct |
35 |
Correct |
475 ms |
17876 KB |
Output is correct |
36 |
Correct |
513 ms |
17940 KB |
Output is correct |
37 |
Correct |
501 ms |
17876 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
52 ms |
3184 KB |
Output is correct |
40 |
Correct |
61 ms |
3196 KB |
Output is correct |
41 |
Correct |
49 ms |
3184 KB |
Output is correct |
42 |
Correct |
46 ms |
3184 KB |
Output is correct |
43 |
Correct |
47 ms |
3184 KB |
Output is correct |
44 |
Correct |
46 ms |
3188 KB |
Output is correct |
45 |
Correct |
58 ms |
3192 KB |
Output is correct |
46 |
Correct |
51 ms |
3184 KB |
Output is correct |
47 |
Correct |
45 ms |
3192 KB |
Output is correct |
48 |
Correct |
49 ms |
3184 KB |
Output is correct |
49 |
Correct |
48 ms |
3192 KB |
Output is correct |
50 |
Correct |
58 ms |
3064 KB |
Output is correct |
51 |
Correct |
496 ms |
17364 KB |
Output is correct |
52 |
Correct |
462 ms |
17912 KB |
Output is correct |
53 |
Correct |
520 ms |
17620 KB |
Output is correct |
54 |
Correct |
55 ms |
2928 KB |
Output is correct |
55 |
Correct |
43 ms |
2928 KB |
Output is correct |
56 |
Correct |
164 ms |
8928 KB |
Output is correct |
57 |
Correct |
0 ms |
384 KB |
Output is correct |
58 |
Correct |
50 ms |
2936 KB |
Output is correct |
59 |
Correct |
48 ms |
2924 KB |
Output is correct |
60 |
Correct |
522 ms |
17284 KB |
Output is correct |
61 |
Correct |
48 ms |
3064 KB |
Output is correct |
62 |
Correct |
46 ms |
2928 KB |
Output is correct |
63 |
Correct |
46 ms |
2932 KB |
Output is correct |
64 |
Correct |
48 ms |
2936 KB |
Output is correct |
65 |
Correct |
49 ms |
2936 KB |
Output is correct |
66 |
Correct |
49 ms |
2928 KB |
Output is correct |
67 |
Correct |
47 ms |
2936 KB |
Output is correct |
68 |
Correct |
45 ms |
2928 KB |
Output is correct |
69 |
Correct |
58 ms |
2928 KB |
Output is correct |
70 |
Correct |
505 ms |
17236 KB |
Output is correct |
71 |
Correct |
49 ms |
2928 KB |
Output is correct |
72 |
Correct |
459 ms |
17492 KB |
Output is correct |
73 |
Correct |
455 ms |
17492 KB |
Output is correct |
74 |
Correct |
1 ms |
384 KB |
Output is correct |
75 |
Correct |
1 ms |
384 KB |
Output is correct |
76 |
Correct |
0 ms |
384 KB |
Output is correct |
77 |
Correct |
0 ms |
384 KB |
Output is correct |
78 |
Correct |
0 ms |
384 KB |
Output is correct |
79 |
Correct |
6 ms |
1152 KB |
Output is correct |
80 |
Correct |
532 ms |
17236 KB |
Output is correct |
81 |
Correct |
552 ms |
17236 KB |
Output is correct |
82 |
Correct |
549 ms |
17236 KB |
Output is correct |
83 |
Correct |
514 ms |
17236 KB |
Output is correct |
84 |
Correct |
488 ms |
17236 KB |
Output is correct |
85 |
Correct |
491 ms |
17364 KB |
Output is correct |
86 |
Correct |
163 ms |
8964 KB |
Output is correct |
87 |
Correct |
1 ms |
384 KB |
Output is correct |