Submission #836753

# Submission time Handle Problem Language Result Execution time Memory
836753 2023-08-24T15:09:28 Z nonono Strange Device (APIO19_strange_device) C++14
100 / 100
574 ms 68984 KB
#include <bits/stdc++.h>
using namespace std;

const long long inf = 1e18;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    long long n, a, b;
    cin >> n >> a >> b;

    long long k = a / __gcd(a, b + 1);
    long long x = 1;

    if(inf / k < b) x = inf + 5;
    else x = b * k;

    vector<pair<long long, bool>> p;

    for(int i = 1; i <= n; i ++) {
        long long l, r;
        cin >> l >> r;

        if(r - l + 1 >= x) {
            cout << x << "\n";
            return 0;
        }

        long long L = l % x;
        long long R = r % x;

        if(L <= R) {
            p.push_back({L, true});
            p.push_back({R + 1, false});
        } else {
            p.push_back({L, true});
            p.push_back({x, false});

            p.push_back({0, true});
            p.push_back({R + 1, false});
        }
    }

    sort(p.begin(), p.end());

    long long total = 0;
    int cnt = 0;
    for(int i = 0; i < p.size(); i ++) {
        if(cnt) {
            total += p[i].first - p[i - 1].first;
        }

        cnt += (p[i].second ? 1 : -1);
    }

    cout << total << "\n";
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0; i < p.size(); i ++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 1240 KB Output is correct
3 Correct 4 ms 1240 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1240 KB Output is correct
17 Correct 45 ms 7256 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 265 ms 56824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 393 ms 68828 KB Output is correct
3 Correct 404 ms 68780 KB Output is correct
4 Correct 372 ms 68836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 393 ms 68828 KB Output is correct
3 Correct 404 ms 68780 KB Output is correct
4 Correct 372 ms 68836 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 409 ms 68788 KB Output is correct
7 Correct 418 ms 68808 KB Output is correct
8 Correct 397 ms 68752 KB Output is correct
9 Correct 455 ms 68880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 393 ms 68828 KB Output is correct
3 Correct 404 ms 68780 KB Output is correct
4 Correct 372 ms 68836 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 37 ms 7232 KB Output is correct
7 Correct 42 ms 7252 KB Output is correct
8 Correct 38 ms 7292 KB Output is correct
9 Correct 37 ms 7208 KB Output is correct
10 Correct 39 ms 7292 KB Output is correct
11 Correct 39 ms 7228 KB Output is correct
12 Correct 45 ms 7276 KB Output is correct
13 Correct 42 ms 7260 KB Output is correct
14 Correct 38 ms 7232 KB Output is correct
15 Correct 43 ms 7288 KB Output is correct
16 Correct 42 ms 7244 KB Output is correct
17 Correct 38 ms 7232 KB Output is correct
18 Correct 441 ms 68772 KB Output is correct
19 Correct 369 ms 68768 KB Output is correct
20 Correct 472 ms 68836 KB Output is correct
21 Correct 47 ms 7232 KB Output is correct
22 Correct 41 ms 7268 KB Output is correct
23 Correct 107 ms 26616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 42 ms 7232 KB Output is correct
3 Correct 42 ms 7244 KB Output is correct
4 Correct 541 ms 68984 KB Output is correct
5 Correct 41 ms 7168 KB Output is correct
6 Correct 43 ms 7256 KB Output is correct
7 Correct 41 ms 7200 KB Output is correct
8 Correct 43 ms 7228 KB Output is correct
9 Correct 41 ms 7228 KB Output is correct
10 Correct 43 ms 7244 KB Output is correct
11 Correct 43 ms 7184 KB Output is correct
12 Correct 37 ms 7228 KB Output is correct
13 Correct 44 ms 7236 KB Output is correct
14 Correct 474 ms 68856 KB Output is correct
15 Correct 44 ms 7232 KB Output is correct
16 Correct 371 ms 68764 KB Output is correct
17 Correct 397 ms 68808 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 1240 KB Output is correct
3 Correct 4 ms 1240 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1240 KB Output is correct
17 Correct 45 ms 7256 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 265 ms 56824 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 393 ms 68828 KB Output is correct
31 Correct 404 ms 68780 KB Output is correct
32 Correct 372 ms 68836 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 409 ms 68788 KB Output is correct
35 Correct 418 ms 68808 KB Output is correct
36 Correct 397 ms 68752 KB Output is correct
37 Correct 455 ms 68880 KB Output is correct
38 Correct 0 ms 336 KB Output is correct
39 Correct 37 ms 7232 KB Output is correct
40 Correct 42 ms 7252 KB Output is correct
41 Correct 38 ms 7292 KB Output is correct
42 Correct 37 ms 7208 KB Output is correct
43 Correct 39 ms 7292 KB Output is correct
44 Correct 39 ms 7228 KB Output is correct
45 Correct 45 ms 7276 KB Output is correct
46 Correct 42 ms 7260 KB Output is correct
47 Correct 38 ms 7232 KB Output is correct
48 Correct 43 ms 7288 KB Output is correct
49 Correct 42 ms 7244 KB Output is correct
50 Correct 38 ms 7232 KB Output is correct
51 Correct 441 ms 68772 KB Output is correct
52 Correct 369 ms 68768 KB Output is correct
53 Correct 472 ms 68836 KB Output is correct
54 Correct 47 ms 7232 KB Output is correct
55 Correct 41 ms 7268 KB Output is correct
56 Correct 107 ms 26616 KB Output is correct
57 Correct 1 ms 336 KB Output is correct
58 Correct 42 ms 7232 KB Output is correct
59 Correct 42 ms 7244 KB Output is correct
60 Correct 541 ms 68984 KB Output is correct
61 Correct 41 ms 7168 KB Output is correct
62 Correct 43 ms 7256 KB Output is correct
63 Correct 41 ms 7200 KB Output is correct
64 Correct 43 ms 7228 KB Output is correct
65 Correct 41 ms 7228 KB Output is correct
66 Correct 43 ms 7244 KB Output is correct
67 Correct 43 ms 7184 KB Output is correct
68 Correct 37 ms 7228 KB Output is correct
69 Correct 44 ms 7236 KB Output is correct
70 Correct 474 ms 68856 KB Output is correct
71 Correct 44 ms 7232 KB Output is correct
72 Correct 371 ms 68764 KB Output is correct
73 Correct 397 ms 68808 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 316 KB Output is correct
79 Correct 4 ms 1240 KB Output is correct
80 Correct 551 ms 68760 KB Output is correct
81 Correct 574 ms 68788 KB Output is correct
82 Correct 460 ms 68764 KB Output is correct
83 Correct 476 ms 68852 KB Output is correct
84 Correct 463 ms 68780 KB Output is correct
85 Correct 448 ms 68828 KB Output is correct
86 Correct 104 ms 26612 KB Output is correct
87 Correct 0 ms 212 KB Output is correct