# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
343982 | 2021-01-05T01:44:39 Z | spatarel | Strange Device (APIO19_strange_device) | C++17 | 792 ms | 34232 KB |
#include <stdio.h> #include <algorithm> #include <vector> struct Event { long long index; int add; }; bool operator < (const Event &a, const Event &b) { return a.index < b.index; } long long gcd(long long a, long long b) { long long r = a % b; while (r > 0) { a = b; b = r; r = a % b; } return b; } int main() { int n; long long A, B; scanf("%d%lld%lld", &n, &A, &B); long long AB = A / gcd(A, B + 1); if (AB < 2e18 / B) { // AB * B < 2e18 AB *= B; } else { AB = 2e18; } bool allMarked = false; std::vector<Event> events; for (int i = 0; i < n; i++) { long long l, r; scanf("%lld%lld", &l, &r); if (r - l + 1 >= AB) { allMarked = true; } else { l %= AB; r %= AB; events.push_back(Event{l, +1}); events.push_back(Event{r + 1, -1}); if (l > r) { events.push_back(Event{0, +1}); events.push_back(Event{AB, -1}); } } } std::sort(events.begin(), events.end()); int currentValue = 0; long long answer = 0; if (allMarked) { answer = AB; } else { long long currentPosition = 0; for (Event event : events) { if (currentValue > 0) { answer += event.index - currentPosition; } currentValue += event.add; currentPosition = event.index; /* printf("%lld %d (%d %lld)\n", event.index, event.add, currentValue, answer);//*/ } } printf("%lld\n", answer); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Correct | 7 ms | 1384 KB | Output is correct |
3 | Correct | 7 ms | 1512 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 0 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 0 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 7 ms | 1384 KB | Output is correct |
17 | Correct | 75 ms | 7260 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 364 KB | Output is correct |
5 | Correct | 439 ms | 33716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 364 KB | Output is correct |
2 | Correct | 652 ms | 33972 KB | Output is correct |
3 | Correct | 701 ms | 34100 KB | Output is correct |
4 | Correct | 622 ms | 34232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 364 KB | Output is correct |
2 | Correct | 652 ms | 33972 KB | Output is correct |
3 | Correct | 701 ms | 34100 KB | Output is correct |
4 | Correct | 622 ms | 34232 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 660 ms | 34100 KB | Output is correct |
7 | Correct | 640 ms | 34100 KB | Output is correct |
8 | Correct | 637 ms | 34100 KB | Output is correct |
9 | Correct | 754 ms | 34228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 364 KB | Output is correct |
2 | Correct | 652 ms | 33972 KB | Output is correct |
3 | Correct | 701 ms | 34100 KB | Output is correct |
4 | Correct | 622 ms | 34232 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 77 ms | 7260 KB | Output is correct |
7 | Correct | 65 ms | 7260 KB | Output is correct |
8 | Correct | 57 ms | 7260 KB | Output is correct |
9 | Correct | 62 ms | 7260 KB | Output is correct |
10 | Correct | 58 ms | 7332 KB | Output is correct |
11 | Correct | 62 ms | 7260 KB | Output is correct |
12 | Correct | 62 ms | 7260 KB | Output is correct |
13 | Correct | 77 ms | 7380 KB | Output is correct |
14 | Correct | 57 ms | 7260 KB | Output is correct |
15 | Correct | 71 ms | 7260 KB | Output is correct |
16 | Correct | 71 ms | 7260 KB | Output is correct |
17 | Correct | 60 ms | 7260 KB | Output is correct |
18 | Correct | 680 ms | 34100 KB | Output is correct |
19 | Correct | 621 ms | 34100 KB | Output is correct |
20 | Correct | 771 ms | 34100 KB | Output is correct |
21 | Correct | 78 ms | 7260 KB | Output is correct |
22 | Correct | 55 ms | 7260 KB | Output is correct |
23 | Correct | 194 ms | 26696 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Correct | 91 ms | 7260 KB | Output is correct |
3 | Correct | 70 ms | 7260 KB | Output is correct |
4 | Correct | 767 ms | 34100 KB | Output is correct |
5 | Correct | 72 ms | 7260 KB | Output is correct |
6 | Correct | 71 ms | 7384 KB | Output is correct |
7 | Correct | 72 ms | 7260 KB | Output is correct |
8 | Correct | 80 ms | 7260 KB | Output is correct |
9 | Correct | 70 ms | 7260 KB | Output is correct |
10 | Correct | 79 ms | 7384 KB | Output is correct |
11 | Correct | 70 ms | 7260 KB | Output is correct |
12 | Correct | 60 ms | 7260 KB | Output is correct |
13 | Correct | 73 ms | 7260 KB | Output is correct |
14 | Correct | 743 ms | 34228 KB | Output is correct |
15 | Correct | 73 ms | 7260 KB | Output is correct |
16 | Correct | 600 ms | 34212 KB | Output is correct |
17 | Correct | 650 ms | 34100 KB | Output is correct |
18 | Correct | 0 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Correct | 7 ms | 1384 KB | Output is correct |
3 | Correct | 7 ms | 1512 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 0 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 0 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 7 ms | 1384 KB | Output is correct |
17 | Correct | 75 ms | 7260 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 0 ms | 364 KB | Output is correct |
20 | Correct | 0 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 0 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 0 ms | 364 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 2 ms | 364 KB | Output is correct |
28 | Correct | 439 ms | 33716 KB | Output is correct |
29 | Correct | 3 ms | 364 KB | Output is correct |
30 | Correct | 652 ms | 33972 KB | Output is correct |
31 | Correct | 701 ms | 34100 KB | Output is correct |
32 | Correct | 622 ms | 34232 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 660 ms | 34100 KB | Output is correct |
35 | Correct | 640 ms | 34100 KB | Output is correct |
36 | Correct | 637 ms | 34100 KB | Output is correct |
37 | Correct | 754 ms | 34228 KB | Output is correct |
38 | Correct | 0 ms | 364 KB | Output is correct |
39 | Correct | 77 ms | 7260 KB | Output is correct |
40 | Correct | 65 ms | 7260 KB | Output is correct |
41 | Correct | 57 ms | 7260 KB | Output is correct |
42 | Correct | 62 ms | 7260 KB | Output is correct |
43 | Correct | 58 ms | 7332 KB | Output is correct |
44 | Correct | 62 ms | 7260 KB | Output is correct |
45 | Correct | 62 ms | 7260 KB | Output is correct |
46 | Correct | 77 ms | 7380 KB | Output is correct |
47 | Correct | 57 ms | 7260 KB | Output is correct |
48 | Correct | 71 ms | 7260 KB | Output is correct |
49 | Correct | 71 ms | 7260 KB | Output is correct |
50 | Correct | 60 ms | 7260 KB | Output is correct |
51 | Correct | 680 ms | 34100 KB | Output is correct |
52 | Correct | 621 ms | 34100 KB | Output is correct |
53 | Correct | 771 ms | 34100 KB | Output is correct |
54 | Correct | 78 ms | 7260 KB | Output is correct |
55 | Correct | 55 ms | 7260 KB | Output is correct |
56 | Correct | 194 ms | 26696 KB | Output is correct |
57 | Correct | 0 ms | 364 KB | Output is correct |
58 | Correct | 91 ms | 7260 KB | Output is correct |
59 | Correct | 70 ms | 7260 KB | Output is correct |
60 | Correct | 767 ms | 34100 KB | Output is correct |
61 | Correct | 72 ms | 7260 KB | Output is correct |
62 | Correct | 71 ms | 7384 KB | Output is correct |
63 | Correct | 72 ms | 7260 KB | Output is correct |
64 | Correct | 80 ms | 7260 KB | Output is correct |
65 | Correct | 70 ms | 7260 KB | Output is correct |
66 | Correct | 79 ms | 7384 KB | Output is correct |
67 | Correct | 70 ms | 7260 KB | Output is correct |
68 | Correct | 60 ms | 7260 KB | Output is correct |
69 | Correct | 73 ms | 7260 KB | Output is correct |
70 | Correct | 743 ms | 34228 KB | Output is correct |
71 | Correct | 73 ms | 7260 KB | Output is correct |
72 | Correct | 600 ms | 34212 KB | Output is correct |
73 | Correct | 650 ms | 34100 KB | Output is correct |
74 | Correct | 0 ms | 364 KB | Output is correct |
75 | Correct | 1 ms | 364 KB | Output is correct |
76 | Correct | 1 ms | 364 KB | Output is correct |
77 | Correct | 1 ms | 364 KB | Output is correct |
78 | Correct | 1 ms | 364 KB | Output is correct |
79 | Correct | 6 ms | 1384 KB | Output is correct |
80 | Correct | 770 ms | 34112 KB | Output is correct |
81 | Correct | 778 ms | 34100 KB | Output is correct |
82 | Correct | 727 ms | 34100 KB | Output is correct |
83 | Correct | 730 ms | 34100 KB | Output is correct |
84 | Correct | 792 ms | 34100 KB | Output is correct |
85 | Correct | 781 ms | 34220 KB | Output is correct |
86 | Correct | 169 ms | 26696 KB | Output is correct |
87 | Correct | 1 ms | 364 KB | Output is correct |