#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
long long gcd(long long x, long long y)
{
if (x == 0)
return y;
return gcd(y % x, x);
}
long long lca(long long x, long long y)
{
return x / gcd(x, y) * y;
}
long long n, x, y;
long long t;
vector<pair<long long, int> > v;
void ubd(long long l, long long r)
{
v.push_back(m_p(l, 1));
v.push_back(m_p(r + 1, -1));
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
#endif // SOMETHING
cin >> n >> x >> y;
t = x / gcd(y + 1, x) * y;
while (n--)
{
long long l, r;
cin >> l >> r;
if (l / t == r / t)
ubd(l % t, r % t);
else if (l / t == r / t - 1)
{
ubd(0, r % t);
ubd(l % t, t - 1);
}
else
{
ubd(0, t - 1);
}
}
sort(v.begin(), v.end());
long long ans = 0;
int p = 0;
for (int i = 0; i < v.size(); ++i)
{
p += v[i].second;
if (p > 0)
ans += (v[i + 1].first - v[i].first);
}
cout << ans << endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:54:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v.size(); ++i)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
23 ms |
1404 KB |
Output is correct |
3 |
Correct |
22 ms |
1404 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
23 ms |
1404 KB |
Output is correct |
17 |
Correct |
233 ms |
7268 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
1579 ms |
56984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
2253 ms |
69084 KB |
Output is correct |
3 |
Correct |
2288 ms |
69172 KB |
Output is correct |
4 |
Correct |
2210 ms |
69248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
2253 ms |
69084 KB |
Output is correct |
3 |
Correct |
2288 ms |
69172 KB |
Output is correct |
4 |
Correct |
2210 ms |
69248 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
2272 ms |
69160 KB |
Output is correct |
7 |
Correct |
2245 ms |
69196 KB |
Output is correct |
8 |
Correct |
2243 ms |
69436 KB |
Output is correct |
9 |
Correct |
2350 ms |
69300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
2253 ms |
69084 KB |
Output is correct |
3 |
Correct |
2288 ms |
69172 KB |
Output is correct |
4 |
Correct |
2210 ms |
69248 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
234 ms |
7356 KB |
Output is correct |
7 |
Correct |
227 ms |
7408 KB |
Output is correct |
8 |
Correct |
223 ms |
7268 KB |
Output is correct |
9 |
Correct |
225 ms |
7268 KB |
Output is correct |
10 |
Correct |
224 ms |
7268 KB |
Output is correct |
11 |
Correct |
225 ms |
7268 KB |
Output is correct |
12 |
Correct |
223 ms |
7268 KB |
Output is correct |
13 |
Correct |
228 ms |
7488 KB |
Output is correct |
14 |
Correct |
225 ms |
7252 KB |
Output is correct |
15 |
Correct |
241 ms |
7272 KB |
Output is correct |
16 |
Correct |
242 ms |
7412 KB |
Output is correct |
17 |
Correct |
229 ms |
7268 KB |
Output is correct |
18 |
Correct |
2261 ms |
69196 KB |
Output is correct |
19 |
Correct |
2249 ms |
69092 KB |
Output is correct |
20 |
Correct |
2343 ms |
69152 KB |
Output is correct |
21 |
Correct |
236 ms |
7416 KB |
Output is correct |
22 |
Correct |
214 ms |
7272 KB |
Output is correct |
23 |
Correct |
718 ms |
26832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
229 ms |
7272 KB |
Output is correct |
3 |
Correct |
233 ms |
7324 KB |
Output is correct |
4 |
Correct |
2385 ms |
69144 KB |
Output is correct |
5 |
Correct |
228 ms |
7388 KB |
Output is correct |
6 |
Correct |
232 ms |
7352 KB |
Output is correct |
7 |
Correct |
234 ms |
7268 KB |
Output is correct |
8 |
Correct |
233 ms |
7268 KB |
Output is correct |
9 |
Correct |
228 ms |
7272 KB |
Output is correct |
10 |
Correct |
233 ms |
7268 KB |
Output is correct |
11 |
Correct |
231 ms |
7268 KB |
Output is correct |
12 |
Correct |
221 ms |
7268 KB |
Output is correct |
13 |
Correct |
229 ms |
7268 KB |
Output is correct |
14 |
Correct |
2370 ms |
69060 KB |
Output is correct |
15 |
Correct |
231 ms |
7268 KB |
Output is correct |
16 |
Correct |
2218 ms |
69120 KB |
Output is correct |
17 |
Correct |
2237 ms |
69152 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
23 ms |
1404 KB |
Output is correct |
3 |
Correct |
22 ms |
1404 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
23 ms |
1404 KB |
Output is correct |
17 |
Correct |
233 ms |
7268 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
0 ms |
256 KB |
Output is correct |
22 |
Correct |
0 ms |
256 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
256 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
1579 ms |
56984 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
2253 ms |
69084 KB |
Output is correct |
31 |
Correct |
2288 ms |
69172 KB |
Output is correct |
32 |
Correct |
2210 ms |
69248 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
2272 ms |
69160 KB |
Output is correct |
35 |
Correct |
2245 ms |
69196 KB |
Output is correct |
36 |
Correct |
2243 ms |
69436 KB |
Output is correct |
37 |
Correct |
2350 ms |
69300 KB |
Output is correct |
38 |
Correct |
0 ms |
256 KB |
Output is correct |
39 |
Correct |
234 ms |
7356 KB |
Output is correct |
40 |
Correct |
227 ms |
7408 KB |
Output is correct |
41 |
Correct |
223 ms |
7268 KB |
Output is correct |
42 |
Correct |
225 ms |
7268 KB |
Output is correct |
43 |
Correct |
224 ms |
7268 KB |
Output is correct |
44 |
Correct |
225 ms |
7268 KB |
Output is correct |
45 |
Correct |
223 ms |
7268 KB |
Output is correct |
46 |
Correct |
228 ms |
7488 KB |
Output is correct |
47 |
Correct |
225 ms |
7252 KB |
Output is correct |
48 |
Correct |
241 ms |
7272 KB |
Output is correct |
49 |
Correct |
242 ms |
7412 KB |
Output is correct |
50 |
Correct |
229 ms |
7268 KB |
Output is correct |
51 |
Correct |
2261 ms |
69196 KB |
Output is correct |
52 |
Correct |
2249 ms |
69092 KB |
Output is correct |
53 |
Correct |
2343 ms |
69152 KB |
Output is correct |
54 |
Correct |
236 ms |
7416 KB |
Output is correct |
55 |
Correct |
214 ms |
7272 KB |
Output is correct |
56 |
Correct |
718 ms |
26832 KB |
Output is correct |
57 |
Correct |
0 ms |
256 KB |
Output is correct |
58 |
Correct |
229 ms |
7272 KB |
Output is correct |
59 |
Correct |
233 ms |
7324 KB |
Output is correct |
60 |
Correct |
2385 ms |
69144 KB |
Output is correct |
61 |
Correct |
228 ms |
7388 KB |
Output is correct |
62 |
Correct |
232 ms |
7352 KB |
Output is correct |
63 |
Correct |
234 ms |
7268 KB |
Output is correct |
64 |
Correct |
233 ms |
7268 KB |
Output is correct |
65 |
Correct |
228 ms |
7272 KB |
Output is correct |
66 |
Correct |
233 ms |
7268 KB |
Output is correct |
67 |
Correct |
231 ms |
7268 KB |
Output is correct |
68 |
Correct |
221 ms |
7268 KB |
Output is correct |
69 |
Correct |
229 ms |
7268 KB |
Output is correct |
70 |
Correct |
2370 ms |
69060 KB |
Output is correct |
71 |
Correct |
231 ms |
7268 KB |
Output is correct |
72 |
Correct |
2218 ms |
69120 KB |
Output is correct |
73 |
Correct |
2237 ms |
69152 KB |
Output is correct |
74 |
Correct |
0 ms |
256 KB |
Output is correct |
75 |
Correct |
0 ms |
256 KB |
Output is correct |
76 |
Correct |
0 ms |
256 KB |
Output is correct |
77 |
Correct |
0 ms |
256 KB |
Output is correct |
78 |
Correct |
0 ms |
256 KB |
Output is correct |
79 |
Correct |
23 ms |
1396 KB |
Output is correct |
80 |
Correct |
2366 ms |
69132 KB |
Output is correct |
81 |
Correct |
2404 ms |
69044 KB |
Output is correct |
82 |
Correct |
2344 ms |
69276 KB |
Output is correct |
83 |
Correct |
2331 ms |
69192 KB |
Output is correct |
84 |
Correct |
2371 ms |
68952 KB |
Output is correct |
85 |
Correct |
2477 ms |
69092 KB |
Output is correct |
86 |
Correct |
723 ms |
26832 KB |
Output is correct |
87 |
Correct |
1 ms |
256 KB |
Output is correct |