#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 asdf;
typedef pair<asdf, asdf> p;
ll _n, _a, _b;
asdf n, a, b, c, sz;
void print(__int128 x){
string s;
while(x){
s += (char)(x%10 + '0'); x /= 10;
}
reverse(s.begin(), s.end());
cout << s;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> _n >> _a >> _b;
n = _n, a = _a, b = _b;
sz = a / __gcd(a, b+1) * b;
vector<p> v;
for(int i=0; i<n; i++){
ll _l, _r; cin >> _l >> _r;
asdf l, r; l = _l, r = _r;
if(r-l+1 > sz){
print(sz); return 0;
}
l %= sz, r %= sz;
if(l <= r) v.emplace_back(l, r);
else v.emplace_back(l, sz-1), v.emplace_back(0, r);
}
sort(v.begin(), v.end());
asdf ans = 0;
for(int i=0; i<v.size(); i++){
int j = i; asdf now = v[i].second;
while(j < v.size() && v[j].first <= now){
now = max(now, v[j].second); j++;
}
ans += now - v[i].first + 1;
i = j - 1;
}
print(ans);
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++){
~^~~~~~~~~
strange_device.cpp:41:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < v.size() && v[j].first <= now){
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
1400 KB |
Output is correct |
3 |
Correct |
10 ms |
1400 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 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 |
376 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 |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
9 ms |
1320 KB |
Output is correct |
17 |
Correct |
77 ms |
7364 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 |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
428 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
529 ms |
57128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
786 ms |
69000 KB |
Output is correct |
3 |
Correct |
696 ms |
68892 KB |
Output is correct |
4 |
Correct |
700 ms |
69012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
786 ms |
69000 KB |
Output is correct |
3 |
Correct |
696 ms |
68892 KB |
Output is correct |
4 |
Correct |
700 ms |
69012 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
707 ms |
68984 KB |
Output is correct |
7 |
Correct |
709 ms |
68916 KB |
Output is correct |
8 |
Correct |
693 ms |
69024 KB |
Output is correct |
9 |
Correct |
758 ms |
69020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
786 ms |
69000 KB |
Output is correct |
3 |
Correct |
696 ms |
68892 KB |
Output is correct |
4 |
Correct |
700 ms |
69012 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
68 ms |
7336 KB |
Output is correct |
7 |
Correct |
72 ms |
7276 KB |
Output is correct |
8 |
Correct |
70 ms |
7296 KB |
Output is correct |
9 |
Correct |
73 ms |
7272 KB |
Output is correct |
10 |
Correct |
68 ms |
7404 KB |
Output is correct |
11 |
Correct |
71 ms |
7272 KB |
Output is correct |
12 |
Correct |
68 ms |
7396 KB |
Output is correct |
13 |
Correct |
75 ms |
7272 KB |
Output is correct |
14 |
Correct |
71 ms |
7392 KB |
Output is correct |
15 |
Correct |
77 ms |
7400 KB |
Output is correct |
16 |
Correct |
74 ms |
7352 KB |
Output is correct |
17 |
Correct |
71 ms |
7272 KB |
Output is correct |
18 |
Correct |
703 ms |
69072 KB |
Output is correct |
19 |
Correct |
696 ms |
69044 KB |
Output is correct |
20 |
Correct |
772 ms |
69176 KB |
Output is correct |
21 |
Correct |
74 ms |
7272 KB |
Output is correct |
22 |
Correct |
66 ms |
7276 KB |
Output is correct |
23 |
Correct |
221 ms |
26996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
73 ms |
7296 KB |
Output is correct |
3 |
Correct |
76 ms |
7412 KB |
Output is correct |
4 |
Correct |
814 ms |
69180 KB |
Output is correct |
5 |
Correct |
74 ms |
7272 KB |
Output is correct |
6 |
Correct |
76 ms |
7288 KB |
Output is correct |
7 |
Correct |
86 ms |
7424 KB |
Output is correct |
8 |
Correct |
79 ms |
7404 KB |
Output is correct |
9 |
Correct |
75 ms |
7296 KB |
Output is correct |
10 |
Correct |
74 ms |
7372 KB |
Output is correct |
11 |
Correct |
74 ms |
7304 KB |
Output is correct |
12 |
Correct |
66 ms |
7368 KB |
Output is correct |
13 |
Correct |
77 ms |
7272 KB |
Output is correct |
14 |
Correct |
767 ms |
68960 KB |
Output is correct |
15 |
Correct |
73 ms |
7308 KB |
Output is correct |
16 |
Correct |
701 ms |
69072 KB |
Output is correct |
17 |
Correct |
685 ms |
68968 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 |
9 ms |
1400 KB |
Output is correct |
3 |
Correct |
10 ms |
1400 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 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 |
376 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 |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
9 ms |
1320 KB |
Output is correct |
17 |
Correct |
77 ms |
7364 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 |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
428 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
529 ms |
57128 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
786 ms |
69000 KB |
Output is correct |
31 |
Correct |
696 ms |
68892 KB |
Output is correct |
32 |
Correct |
700 ms |
69012 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
707 ms |
68984 KB |
Output is correct |
35 |
Correct |
709 ms |
68916 KB |
Output is correct |
36 |
Correct |
693 ms |
69024 KB |
Output is correct |
37 |
Correct |
758 ms |
69020 KB |
Output is correct |
38 |
Correct |
2 ms |
380 KB |
Output is correct |
39 |
Correct |
68 ms |
7336 KB |
Output is correct |
40 |
Correct |
72 ms |
7276 KB |
Output is correct |
41 |
Correct |
70 ms |
7296 KB |
Output is correct |
42 |
Correct |
73 ms |
7272 KB |
Output is correct |
43 |
Correct |
68 ms |
7404 KB |
Output is correct |
44 |
Correct |
71 ms |
7272 KB |
Output is correct |
45 |
Correct |
68 ms |
7396 KB |
Output is correct |
46 |
Correct |
75 ms |
7272 KB |
Output is correct |
47 |
Correct |
71 ms |
7392 KB |
Output is correct |
48 |
Correct |
77 ms |
7400 KB |
Output is correct |
49 |
Correct |
74 ms |
7352 KB |
Output is correct |
50 |
Correct |
71 ms |
7272 KB |
Output is correct |
51 |
Correct |
703 ms |
69072 KB |
Output is correct |
52 |
Correct |
696 ms |
69044 KB |
Output is correct |
53 |
Correct |
772 ms |
69176 KB |
Output is correct |
54 |
Correct |
74 ms |
7272 KB |
Output is correct |
55 |
Correct |
66 ms |
7276 KB |
Output is correct |
56 |
Correct |
221 ms |
26996 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
73 ms |
7296 KB |
Output is correct |
59 |
Correct |
76 ms |
7412 KB |
Output is correct |
60 |
Correct |
814 ms |
69180 KB |
Output is correct |
61 |
Correct |
74 ms |
7272 KB |
Output is correct |
62 |
Correct |
76 ms |
7288 KB |
Output is correct |
63 |
Correct |
86 ms |
7424 KB |
Output is correct |
64 |
Correct |
79 ms |
7404 KB |
Output is correct |
65 |
Correct |
75 ms |
7296 KB |
Output is correct |
66 |
Correct |
74 ms |
7372 KB |
Output is correct |
67 |
Correct |
74 ms |
7304 KB |
Output is correct |
68 |
Correct |
66 ms |
7368 KB |
Output is correct |
69 |
Correct |
77 ms |
7272 KB |
Output is correct |
70 |
Correct |
767 ms |
68960 KB |
Output is correct |
71 |
Correct |
73 ms |
7308 KB |
Output is correct |
72 |
Correct |
701 ms |
69072 KB |
Output is correct |
73 |
Correct |
685 ms |
68968 KB |
Output is correct |
74 |
Correct |
2 ms |
376 KB |
Output is correct |
75 |
Correct |
2 ms |
380 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 |
9 ms |
1300 KB |
Output is correct |
80 |
Correct |
882 ms |
69044 KB |
Output is correct |
81 |
Correct |
832 ms |
69092 KB |
Output is correct |
82 |
Correct |
777 ms |
69148 KB |
Output is correct |
83 |
Correct |
782 ms |
68948 KB |
Output is correct |
84 |
Correct |
776 ms |
68868 KB |
Output is correct |
85 |
Correct |
768 ms |
68892 KB |
Output is correct |
86 |
Correct |
224 ms |
26860 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |