#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int MAXN = 2e6+5;
map<ll, bool> visited;
vector< pair<ll, ll> > imp;
ll n, a, b;
ll _gcd(ll x, ll y)
{
if(x < y)
swap(x, y);
if(y == 0)
return x;
return _gcd(y, x % y);
}
int main()
{
cin >> n >> a >> b;
ll sum = 0;
ll big = 1;
map<pair<ll, ll>, bool> used;
ll time = 0;
ll gcd_val = _gcd(a, (b+1LL));
if(2e18 / b * gcd_val < a)
{
big = 2e18;
} else
big = a * b / gcd_val;
for(int i = 1; i <= n; i++)
{
ll f, s;
cin >> f >> s;
if(s - f >= big - 1)
{
imp.push_back({0, 1});
imp.push_back({big - 1, 2});
} else
{
if(f % big <= s % big)
{
imp.push_back({f % big, 1});
imp.push_back({s % big, 2});
} else
{
imp.push_back({0, 1});
imp.push_back({s % big, 2});
imp.push_back({f % big, 1});
imp.push_back({big - 1, 2});
}
}
}
// cout << seg[0].sum << "\n";
sort(imp.begin(), imp.end());
ll cnt = 0;
ll ans = 0;
ll last = -1;
for(pair<ll, ll> e : imp)
{
//cout << ans << " " << cnt << " " << last << "\n";
if(last != -1 && cnt > 0)
{
ans += e.first - last;
if(!visited[last])
{
ans++;
visited[last] = true;
}
visited[e.first] = true;
}
if(e.second == 1)
{
cnt++;
last = e.first;
} else
{
cnt--;
last = e.first;
}
}
cout << ans << "\n";
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:21:8: warning: unused variable 'sum' [-Wunused-variable]
21 | ll sum = 0;
| ^~~
strange_device.cpp:24:8: warning: unused variable 'time' [-Wunused-variable]
24 | ll time = 0;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
18 ms |
2224 KB |
Output is correct |
3 |
Correct |
21 ms |
2136 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
18 ms |
2152 KB |
Output is correct |
17 |
Correct |
243 ms |
10300 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 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
960 ms |
33280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1885 ms |
94204 KB |
Output is correct |
3 |
Correct |
2100 ms |
159400 KB |
Output is correct |
4 |
Correct |
2047 ms |
169340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1885 ms |
94204 KB |
Output is correct |
3 |
Correct |
2100 ms |
159400 KB |
Output is correct |
4 |
Correct |
2047 ms |
169340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2165 ms |
169404 KB |
Output is correct |
7 |
Correct |
1923 ms |
106848 KB |
Output is correct |
8 |
Correct |
2149 ms |
169288 KB |
Output is correct |
9 |
Correct |
2143 ms |
169324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1885 ms |
94204 KB |
Output is correct |
3 |
Correct |
2100 ms |
159400 KB |
Output is correct |
4 |
Correct |
2047 ms |
169340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
183 ms |
19560 KB |
Output is correct |
7 |
Correct |
207 ms |
19600 KB |
Output is correct |
8 |
Correct |
184 ms |
19600 KB |
Output is correct |
9 |
Correct |
189 ms |
19604 KB |
Output is correct |
10 |
Correct |
201 ms |
19576 KB |
Output is correct |
11 |
Correct |
201 ms |
19548 KB |
Output is correct |
12 |
Correct |
200 ms |
19684 KB |
Output is correct |
13 |
Correct |
198 ms |
19664 KB |
Output is correct |
14 |
Correct |
194 ms |
19688 KB |
Output is correct |
15 |
Correct |
238 ms |
19600 KB |
Output is correct |
16 |
Correct |
194 ms |
19596 KB |
Output is correct |
17 |
Correct |
186 ms |
19596 KB |
Output is correct |
18 |
Correct |
2221 ms |
169336 KB |
Output is correct |
19 |
Correct |
2177 ms |
169464 KB |
Output is correct |
20 |
Correct |
2305 ms |
169268 KB |
Output is correct |
21 |
Correct |
200 ms |
19576 KB |
Output is correct |
22 |
Correct |
220 ms |
19616 KB |
Output is correct |
23 |
Correct |
444 ms |
26840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
190 ms |
16820 KB |
Output is correct |
3 |
Correct |
188 ms |
16848 KB |
Output is correct |
4 |
Correct |
2268 ms |
158132 KB |
Output is correct |
5 |
Correct |
191 ms |
16788 KB |
Output is correct |
6 |
Correct |
186 ms |
16744 KB |
Output is correct |
7 |
Correct |
195 ms |
16904 KB |
Output is correct |
8 |
Correct |
202 ms |
16844 KB |
Output is correct |
9 |
Correct |
192 ms |
16936 KB |
Output is correct |
10 |
Correct |
189 ms |
16748 KB |
Output is correct |
11 |
Correct |
184 ms |
16752 KB |
Output is correct |
12 |
Correct |
182 ms |
16732 KB |
Output is correct |
13 |
Correct |
196 ms |
16816 KB |
Output is correct |
14 |
Correct |
2300 ms |
158224 KB |
Output is correct |
15 |
Correct |
197 ms |
16816 KB |
Output is correct |
16 |
Correct |
2181 ms |
169376 KB |
Output is correct |
17 |
Correct |
2229 ms |
169372 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 |
18 ms |
2224 KB |
Output is correct |
3 |
Correct |
21 ms |
2136 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
18 ms |
2152 KB |
Output is correct |
17 |
Correct |
243 ms |
10300 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
1 ms |
300 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
960 ms |
33280 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1885 ms |
94204 KB |
Output is correct |
31 |
Correct |
2100 ms |
159400 KB |
Output is correct |
32 |
Correct |
2047 ms |
169340 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
2165 ms |
169404 KB |
Output is correct |
35 |
Correct |
1923 ms |
106848 KB |
Output is correct |
36 |
Correct |
2149 ms |
169288 KB |
Output is correct |
37 |
Correct |
2143 ms |
169324 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
183 ms |
19560 KB |
Output is correct |
40 |
Correct |
207 ms |
19600 KB |
Output is correct |
41 |
Correct |
184 ms |
19600 KB |
Output is correct |
42 |
Correct |
189 ms |
19604 KB |
Output is correct |
43 |
Correct |
201 ms |
19576 KB |
Output is correct |
44 |
Correct |
201 ms |
19548 KB |
Output is correct |
45 |
Correct |
200 ms |
19684 KB |
Output is correct |
46 |
Correct |
198 ms |
19664 KB |
Output is correct |
47 |
Correct |
194 ms |
19688 KB |
Output is correct |
48 |
Correct |
238 ms |
19600 KB |
Output is correct |
49 |
Correct |
194 ms |
19596 KB |
Output is correct |
50 |
Correct |
186 ms |
19596 KB |
Output is correct |
51 |
Correct |
2221 ms |
169336 KB |
Output is correct |
52 |
Correct |
2177 ms |
169464 KB |
Output is correct |
53 |
Correct |
2305 ms |
169268 KB |
Output is correct |
54 |
Correct |
200 ms |
19576 KB |
Output is correct |
55 |
Correct |
220 ms |
19616 KB |
Output is correct |
56 |
Correct |
444 ms |
26840 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
190 ms |
16820 KB |
Output is correct |
59 |
Correct |
188 ms |
16848 KB |
Output is correct |
60 |
Correct |
2268 ms |
158132 KB |
Output is correct |
61 |
Correct |
191 ms |
16788 KB |
Output is correct |
62 |
Correct |
186 ms |
16744 KB |
Output is correct |
63 |
Correct |
195 ms |
16904 KB |
Output is correct |
64 |
Correct |
202 ms |
16844 KB |
Output is correct |
65 |
Correct |
192 ms |
16936 KB |
Output is correct |
66 |
Correct |
189 ms |
16748 KB |
Output is correct |
67 |
Correct |
184 ms |
16752 KB |
Output is correct |
68 |
Correct |
182 ms |
16732 KB |
Output is correct |
69 |
Correct |
196 ms |
16816 KB |
Output is correct |
70 |
Correct |
2300 ms |
158224 KB |
Output is correct |
71 |
Correct |
197 ms |
16816 KB |
Output is correct |
72 |
Correct |
2181 ms |
169376 KB |
Output is correct |
73 |
Correct |
2229 ms |
169372 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
296 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
22 ms |
2116 KB |
Output is correct |
80 |
Correct |
2387 ms |
169316 KB |
Output is correct |
81 |
Correct |
2260 ms |
169440 KB |
Output is correct |
82 |
Correct |
2237 ms |
169380 KB |
Output is correct |
83 |
Correct |
2323 ms |
169260 KB |
Output is correct |
84 |
Correct |
2814 ms |
169200 KB |
Output is correct |
85 |
Correct |
2329 ms |
169304 KB |
Output is correct |
86 |
Correct |
453 ms |
26676 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |