# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
157933 | 2019-10-14T02:32:27 Z | PeppaPig | Strange Device (APIO19_strange_device) | C++14 | 872 ms | 69132 KB |
#include <bits/stdc++.h> #define long long long #define pii pair<long, long> #define x first #define y second using namespace std; const int N = 1e6+5; int n; long A, B, cyc, ans; vector<pii> v; int main() { scanf("%d %lld %lld", &n, &A, &B); bool valid = true; cyc = A / __gcd(B+1, A); if(1e18 / B < A) valid = false; else cyc *= B; for(int i = 1; i <= n; i++) { long l, r; scanf("%lld %lld", &l, &r); if(!valid) ans += r - l + 1; else { if(r - l + 1 >= cyc) v.emplace_back(0, 1), v.emplace_back(cyc, -1); else { l %= cyc, r %= cyc; v.emplace_back(l, 1); v.emplace_back(r + 1, -1); if(l > r) { v.emplace_back(0, 1); v.emplace_back(cyc, -1); } } } } if(!valid) return !printf("%lld\n", ans); sort(v.begin(), v.end()); for(int i = 0, cnt = 0; i < v.size(); ) { int j = i; for( ; v[i].x == v[j].x; j++) cnt += v[j].y; if(cnt) ans += v[j].x - v[i].x; i = j; } printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 8 ms | 1392 KB | Output is correct |
3 | Correct | 9 ms | 1396 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 256 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 | 256 KB | Output is correct |
11 | Correct | 2 ms | 252 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 8 ms | 1396 KB | Output is correct |
17 | Correct | 77 ms | 6932 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 252 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 503 ms | 34348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 681 ms | 34692 KB | Output is correct |
3 | Correct | 703 ms | 34616 KB | Output is correct |
4 | Correct | 660 ms | 34668 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 681 ms | 34692 KB | Output is correct |
3 | Correct | 703 ms | 34616 KB | Output is correct |
4 | Correct | 660 ms | 34668 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 688 ms | 34812 KB | Output is correct |
7 | Correct | 676 ms | 34580 KB | Output is correct |
8 | Correct | 683 ms | 34724 KB | Output is correct |
9 | Correct | 774 ms | 34568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 681 ms | 34692 KB | Output is correct |
3 | Correct | 703 ms | 34616 KB | Output is correct |
4 | Correct | 660 ms | 34668 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 67 ms | 6628 KB | Output is correct |
7 | Correct | 76 ms | 6500 KB | Output is correct |
8 | Correct | 64 ms | 6500 KB | Output is correct |
9 | Correct | 67 ms | 6468 KB | Output is correct |
10 | Correct | 63 ms | 6500 KB | Output is correct |
11 | Correct | 69 ms | 6500 KB | Output is correct |
12 | Correct | 64 ms | 6500 KB | Output is correct |
13 | Correct | 74 ms | 6500 KB | Output is correct |
14 | Correct | 65 ms | 6500 KB | Output is correct |
15 | Correct | 79 ms | 6740 KB | Output is correct |
16 | Correct | 76 ms | 6500 KB | Output is correct |
17 | Correct | 68 ms | 6628 KB | Output is correct |
18 | Correct | 713 ms | 34696 KB | Output is correct |
19 | Correct | 641 ms | 34648 KB | Output is correct |
20 | Correct | 766 ms | 34612 KB | Output is correct |
21 | Correct | 77 ms | 5732 KB | Output is correct |
22 | Correct | 58 ms | 5908 KB | Output is correct |
23 | Correct | 225 ms | 17780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 72 ms | 5732 KB | Output is correct |
3 | Correct | 73 ms | 5732 KB | Output is correct |
4 | Correct | 841 ms | 34624 KB | Output is correct |
5 | Correct | 73 ms | 5816 KB | Output is correct |
6 | Correct | 73 ms | 5808 KB | Output is correct |
7 | Correct | 72 ms | 5768 KB | Output is correct |
8 | Correct | 77 ms | 5732 KB | Output is correct |
9 | Correct | 71 ms | 5832 KB | Output is correct |
10 | Correct | 75 ms | 5604 KB | Output is correct |
11 | Correct | 75 ms | 5732 KB | Output is correct |
12 | Correct | 65 ms | 5732 KB | Output is correct |
13 | Correct | 78 ms | 5732 KB | Output is correct |
14 | Correct | 770 ms | 34504 KB | Output is correct |
15 | Correct | 77 ms | 5092 KB | Output is correct |
16 | Correct | 644 ms | 34388 KB | Output is correct |
17 | Correct | 676 ms | 34496 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 8 ms | 1392 KB | Output is correct |
3 | Correct | 9 ms | 1396 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 256 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 | 256 KB | Output is correct |
11 | Correct | 2 ms | 252 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Correct | 8 ms | 1396 KB | Output is correct |
17 | Correct | 77 ms | 6932 KB | Output is correct |
18 | Correct | 2 ms | 256 KB | Output is correct |
19 | Correct | 2 ms | 256 KB | Output is correct |
20 | Correct | 2 ms | 256 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 252 KB | Output is correct |
23 | Correct | 2 ms | 256 KB | Output is correct |
24 | Correct | 2 ms | 256 KB | Output is correct |
25 | Correct | 2 ms | 376 KB | Output is correct |
26 | Correct | 3 ms | 376 KB | Output is correct |
27 | Correct | 3 ms | 376 KB | Output is correct |
28 | Correct | 503 ms | 34348 KB | Output is correct |
29 | Correct | 2 ms | 256 KB | Output is correct |
30 | Correct | 681 ms | 34692 KB | Output is correct |
31 | Correct | 703 ms | 34616 KB | Output is correct |
32 | Correct | 660 ms | 34668 KB | Output is correct |
33 | Correct | 2 ms | 256 KB | Output is correct |
34 | Correct | 688 ms | 34812 KB | Output is correct |
35 | Correct | 676 ms | 34580 KB | Output is correct |
36 | Correct | 683 ms | 34724 KB | Output is correct |
37 | Correct | 774 ms | 34568 KB | Output is correct |
38 | Correct | 2 ms | 256 KB | Output is correct |
39 | Correct | 67 ms | 6628 KB | Output is correct |
40 | Correct | 76 ms | 6500 KB | Output is correct |
41 | Correct | 64 ms | 6500 KB | Output is correct |
42 | Correct | 67 ms | 6468 KB | Output is correct |
43 | Correct | 63 ms | 6500 KB | Output is correct |
44 | Correct | 69 ms | 6500 KB | Output is correct |
45 | Correct | 64 ms | 6500 KB | Output is correct |
46 | Correct | 74 ms | 6500 KB | Output is correct |
47 | Correct | 65 ms | 6500 KB | Output is correct |
48 | Correct | 79 ms | 6740 KB | Output is correct |
49 | Correct | 76 ms | 6500 KB | Output is correct |
50 | Correct | 68 ms | 6628 KB | Output is correct |
51 | Correct | 713 ms | 34696 KB | Output is correct |
52 | Correct | 641 ms | 34648 KB | Output is correct |
53 | Correct | 766 ms | 34612 KB | Output is correct |
54 | Correct | 77 ms | 5732 KB | Output is correct |
55 | Correct | 58 ms | 5908 KB | Output is correct |
56 | Correct | 225 ms | 17780 KB | Output is correct |
57 | Correct | 2 ms | 256 KB | Output is correct |
58 | Correct | 72 ms | 5732 KB | Output is correct |
59 | Correct | 73 ms | 5732 KB | Output is correct |
60 | Correct | 841 ms | 34624 KB | Output is correct |
61 | Correct | 73 ms | 5816 KB | Output is correct |
62 | Correct | 73 ms | 5808 KB | Output is correct |
63 | Correct | 72 ms | 5768 KB | Output is correct |
64 | Correct | 77 ms | 5732 KB | Output is correct |
65 | Correct | 71 ms | 5832 KB | Output is correct |
66 | Correct | 75 ms | 5604 KB | Output is correct |
67 | Correct | 75 ms | 5732 KB | Output is correct |
68 | Correct | 65 ms | 5732 KB | Output is correct |
69 | Correct | 78 ms | 5732 KB | Output is correct |
70 | Correct | 770 ms | 34504 KB | Output is correct |
71 | Correct | 77 ms | 5092 KB | Output is correct |
72 | Correct | 644 ms | 34388 KB | Output is correct |
73 | Correct | 676 ms | 34496 KB | Output is correct |
74 | Correct | 2 ms | 376 KB | Output is correct |
75 | Correct | 2 ms | 504 KB | Output is correct |
76 | Correct | 2 ms | 256 KB | Output is correct |
77 | Correct | 2 ms | 392 KB | Output is correct |
78 | Correct | 2 ms | 376 KB | Output is correct |
79 | Correct | 8 ms | 1264 KB | Output is correct |
80 | Correct | 872 ms | 68980 KB | Output is correct |
81 | Correct | 854 ms | 68888 KB | Output is correct |
82 | Correct | 744 ms | 68892 KB | Output is correct |
83 | Correct | 780 ms | 68840 KB | Output is correct |
84 | Correct | 775 ms | 69132 KB | Output is correct |
85 | Correct | 801 ms | 68960 KB | Output is correct |
86 | Correct | 230 ms | 26672 KB | Output is correct |
87 | Correct | 2 ms | 256 KB | Output is correct |