Submission #322572

# Submission time Handle Problem Language Result Execution time Memory
322572 2020-11-14T23:26:35 Z arbor Strange Device (APIO19_strange_device) C++14
100 / 100
629 ms 53572 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
using ull = unsigned long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    ull n, a, b; cin >> n >> a >> b;
    ull p = a / __gcd(a, b + 1) * b;
    vector<pair<ull, ull>> v;
    for (int i = 0; i < n; i++) {
        ull l, r; cin >> l >> r;
        if (r - l + 1 >= p) {
            cout << p;
            return 0;
        }
        l %= p, r %= p;
        if (l > r) v.emplace_back(0, r), v.emplace_back(l, p - 1);
        else v.emplace_back(l, r);
    }
    v.emplace_back(p, p);
    sort(all(v));
    ull ans = 0;
    for (int i = 0; i < v.size();) {
        int j = i;
        for (; v[i].second >= v[j].second && j < v.size(); j++);
        ans += v[i].second - v[i].first + 1;
        v[j].first = max(v[j].first, v[i].second + 1);
        i = j;
    }
    cout << ans - 1 << '\n';
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < n; i++) {
      |                     ~~^~~
strange_device.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long unsigned int, long long unsigned int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 0; i < v.size();) {
      |                     ~~^~~~~~~~~~
strange_device.cpp:29:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long unsigned int, long long unsigned int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (; v[i].second >= v[j].second && j < v.size(); j++);
      |                                              ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 748 KB Output is correct
3 Correct 9 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 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 0 ms 364 KB Output is correct
11 Correct 1 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 6 ms 748 KB Output is correct
17 Correct 59 ms 2536 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 384 KB Output is correct
5 Correct 405 ms 17120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 583 ms 16992 KB Output is correct
3 Correct 594 ms 16848 KB Output is correct
4 Correct 524 ms 16848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 583 ms 16992 KB Output is correct
3 Correct 594 ms 16848 KB Output is correct
4 Correct 524 ms 16848 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 629 ms 17024 KB Output is correct
7 Correct 582 ms 16848 KB Output is correct
8 Correct 534 ms 16848 KB Output is correct
9 Correct 582 ms 16976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 583 ms 16992 KB Output is correct
3 Correct 594 ms 16848 KB Output is correct
4 Correct 524 ms 16848 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 52 ms 2536 KB Output is correct
7 Correct 58 ms 2536 KB Output is correct
8 Correct 53 ms 2536 KB Output is correct
9 Correct 53 ms 2536 KB Output is correct
10 Correct 53 ms 2652 KB Output is correct
11 Correct 62 ms 2580 KB Output is correct
12 Correct 60 ms 2536 KB Output is correct
13 Correct 64 ms 2536 KB Output is correct
14 Correct 53 ms 2536 KB Output is correct
15 Correct 61 ms 2536 KB Output is correct
16 Correct 56 ms 2536 KB Output is correct
17 Correct 54 ms 2536 KB Output is correct
18 Correct 550 ms 16848 KB Output is correct
19 Correct 565 ms 16980 KB Output is correct
20 Correct 590 ms 16848 KB Output is correct
21 Correct 60 ms 2664 KB Output is correct
22 Correct 52 ms 2536 KB Output is correct
23 Correct 171 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 56 ms 2692 KB Output is correct
3 Correct 56 ms 2536 KB Output is correct
4 Correct 615 ms 16896 KB Output is correct
5 Correct 56 ms 2536 KB Output is correct
6 Correct 56 ms 2536 KB Output is correct
7 Correct 56 ms 2536 KB Output is correct
8 Correct 57 ms 2536 KB Output is correct
9 Correct 55 ms 2536 KB Output is correct
10 Correct 56 ms 2536 KB Output is correct
11 Correct 57 ms 2536 KB Output is correct
12 Correct 58 ms 2536 KB Output is correct
13 Correct 58 ms 2536 KB Output is correct
14 Correct 590 ms 16888 KB Output is correct
15 Correct 57 ms 2536 KB Output is correct
16 Correct 533 ms 16848 KB Output is correct
17 Correct 540 ms 16976 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 748 KB Output is correct
3 Correct 9 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 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 0 ms 364 KB Output is correct
11 Correct 1 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 6 ms 748 KB Output is correct
17 Correct 59 ms 2536 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 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 1 ms 384 KB Output is correct
28 Correct 405 ms 17120 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 583 ms 16992 KB Output is correct
31 Correct 594 ms 16848 KB Output is correct
32 Correct 524 ms 16848 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 629 ms 17024 KB Output is correct
35 Correct 582 ms 16848 KB Output is correct
36 Correct 534 ms 16848 KB Output is correct
37 Correct 582 ms 16976 KB Output is correct
38 Correct 0 ms 364 KB Output is correct
39 Correct 52 ms 2536 KB Output is correct
40 Correct 58 ms 2536 KB Output is correct
41 Correct 53 ms 2536 KB Output is correct
42 Correct 53 ms 2536 KB Output is correct
43 Correct 53 ms 2652 KB Output is correct
44 Correct 62 ms 2580 KB Output is correct
45 Correct 60 ms 2536 KB Output is correct
46 Correct 64 ms 2536 KB Output is correct
47 Correct 53 ms 2536 KB Output is correct
48 Correct 61 ms 2536 KB Output is correct
49 Correct 56 ms 2536 KB Output is correct
50 Correct 54 ms 2536 KB Output is correct
51 Correct 550 ms 16848 KB Output is correct
52 Correct 565 ms 16980 KB Output is correct
53 Correct 590 ms 16848 KB Output is correct
54 Correct 60 ms 2664 KB Output is correct
55 Correct 52 ms 2536 KB Output is correct
56 Correct 171 ms 8796 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 56 ms 2692 KB Output is correct
59 Correct 56 ms 2536 KB Output is correct
60 Correct 615 ms 16896 KB Output is correct
61 Correct 56 ms 2536 KB Output is correct
62 Correct 56 ms 2536 KB Output is correct
63 Correct 56 ms 2536 KB Output is correct
64 Correct 57 ms 2536 KB Output is correct
65 Correct 55 ms 2536 KB Output is correct
66 Correct 56 ms 2536 KB Output is correct
67 Correct 57 ms 2536 KB Output is correct
68 Correct 58 ms 2536 KB Output is correct
69 Correct 58 ms 2536 KB Output is correct
70 Correct 590 ms 16888 KB Output is correct
71 Correct 57 ms 2536 KB Output is correct
72 Correct 533 ms 16848 KB Output is correct
73 Correct 540 ms 16976 KB Output is correct
74 Correct 1 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 1132 KB Output is correct
80 Correct 623 ms 53472 KB Output is correct
81 Correct 623 ms 53308 KB Output is correct
82 Correct 597 ms 53380 KB Output is correct
83 Correct 592 ms 53308 KB Output is correct
84 Correct 596 ms 53308 KB Output is correct
85 Correct 590 ms 53572 KB Output is correct
86 Correct 174 ms 18524 KB Output is correct
87 Correct 1 ms 364 KB Output is correct