Submission #171603

# Submission time Handle Problem Language Result Execution time Memory
171603 2019-12-29T11:17:41 Z rama_pang Strange Device (APIO19_strange_device) C++14
100 / 100
611 ms 18316 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e18 + 100;

int main() {
    int n;
    lint A, B;
    scanf("%d %lld %lld", &n, &A, &B);

    lint g = __gcd(A, B + 1);
    lint t = 0;

    if ((A / g) > (INF / B + 1)) {
        t = INF;
    } else {
        t = (A / g) * B;
    }

    vector<pair<lint, lint>> interval;
    interval.reserve(2 * n);
    
    for (int i = 0; i < n; i++) {
        lint l, r;
        scanf("%lld %lld", &l, &r);

        if (r - l + 1 >= t) {
            interval.emplace_back(0, t - 1);
        } else {
            l %= t, r %= t;
            if (l <= r) {
                interval.emplace_back(l, r);
            } else {
                interval.emplace_back(l, t - 1);
                interval.emplace_back(0, r);
            }
        }
    }

    sort(begin(interval), end(interval));
    lint ans = 0;

    for (int i = 0; i < (int)interval.size(); i++) {
        lint l = interval[i].first;
        lint r = interval[i].second;
        int nxt = i;
        while (nxt + 1 < (int)interval.size() && interval[nxt + 1].first <= r) {
            r = max(r, interval[nxt + 1].second);
            nxt++;
        }
        ans += (r - l + 1);
        i = nxt;
    }

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

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld %lld", &n, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 8 ms 888 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 884 KB Output is correct
17 Correct 60 ms 3708 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 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 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 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 411 ms 16236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 544 ms 18316 KB Output is correct
3 Correct 518 ms 16260 KB Output is correct
4 Correct 509 ms 16104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 544 ms 18316 KB Output is correct
3 Correct 518 ms 16260 KB Output is correct
4 Correct 509 ms 16104 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 548 ms 16264 KB Output is correct
7 Correct 541 ms 16248 KB Output is correct
8 Correct 525 ms 16316 KB Output is correct
9 Correct 583 ms 17832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 544 ms 18316 KB Output is correct
3 Correct 518 ms 16260 KB Output is correct
4 Correct 509 ms 16104 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 54 ms 3664 KB Output is correct
7 Correct 59 ms 3832 KB Output is correct
8 Correct 51 ms 3704 KB Output is correct
9 Correct 56 ms 3832 KB Output is correct
10 Correct 55 ms 3720 KB Output is correct
11 Correct 58 ms 3704 KB Output is correct
12 Correct 54 ms 3772 KB Output is correct
13 Correct 57 ms 3704 KB Output is correct
14 Correct 53 ms 3704 KB Output is correct
15 Correct 59 ms 3816 KB Output is correct
16 Correct 57 ms 3704 KB Output is correct
17 Correct 55 ms 3684 KB Output is correct
18 Correct 533 ms 17796 KB Output is correct
19 Correct 519 ms 17800 KB Output is correct
20 Correct 573 ms 17784 KB Output is correct
21 Correct 56 ms 3704 KB Output is correct
22 Correct 49 ms 3684 KB Output is correct
23 Correct 203 ms 7120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 58 ms 2552 KB Output is correct
3 Correct 57 ms 3704 KB Output is correct
4 Correct 585 ms 16168 KB Output is correct
5 Correct 64 ms 3812 KB Output is correct
6 Correct 56 ms 3704 KB Output is correct
7 Correct 56 ms 3704 KB Output is correct
8 Correct 58 ms 3660 KB Output is correct
9 Correct 56 ms 3704 KB Output is correct
10 Correct 56 ms 3704 KB Output is correct
11 Correct 58 ms 3704 KB Output is correct
12 Correct 51 ms 3704 KB Output is correct
13 Correct 58 ms 3704 KB Output is correct
14 Correct 580 ms 17668 KB Output is correct
15 Correct 56 ms 3772 KB Output is correct
16 Correct 526 ms 17656 KB Output is correct
17 Correct 525 ms 16248 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 8 ms 888 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 884 KB Output is correct
17 Correct 60 ms 3708 KB Output is correct
18 Correct 2 ms 376 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 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 380 KB Output is correct
28 Correct 411 ms 16236 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 544 ms 18316 KB Output is correct
31 Correct 518 ms 16260 KB Output is correct
32 Correct 509 ms 16104 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 548 ms 16264 KB Output is correct
35 Correct 541 ms 16248 KB Output is correct
36 Correct 525 ms 16316 KB Output is correct
37 Correct 583 ms 17832 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 54 ms 3664 KB Output is correct
40 Correct 59 ms 3832 KB Output is correct
41 Correct 51 ms 3704 KB Output is correct
42 Correct 56 ms 3832 KB Output is correct
43 Correct 55 ms 3720 KB Output is correct
44 Correct 58 ms 3704 KB Output is correct
45 Correct 54 ms 3772 KB Output is correct
46 Correct 57 ms 3704 KB Output is correct
47 Correct 53 ms 3704 KB Output is correct
48 Correct 59 ms 3816 KB Output is correct
49 Correct 57 ms 3704 KB Output is correct
50 Correct 55 ms 3684 KB Output is correct
51 Correct 533 ms 17796 KB Output is correct
52 Correct 519 ms 17800 KB Output is correct
53 Correct 573 ms 17784 KB Output is correct
54 Correct 56 ms 3704 KB Output is correct
55 Correct 49 ms 3684 KB Output is correct
56 Correct 203 ms 7120 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 58 ms 2552 KB Output is correct
59 Correct 57 ms 3704 KB Output is correct
60 Correct 585 ms 16168 KB Output is correct
61 Correct 64 ms 3812 KB Output is correct
62 Correct 56 ms 3704 KB Output is correct
63 Correct 56 ms 3704 KB Output is correct
64 Correct 58 ms 3660 KB Output is correct
65 Correct 56 ms 3704 KB Output is correct
66 Correct 56 ms 3704 KB Output is correct
67 Correct 58 ms 3704 KB Output is correct
68 Correct 51 ms 3704 KB Output is correct
69 Correct 58 ms 3704 KB Output is correct
70 Correct 580 ms 17668 KB Output is correct
71 Correct 56 ms 3772 KB Output is correct
72 Correct 526 ms 17656 KB Output is correct
73 Correct 525 ms 16248 KB Output is correct
74 Correct 2 ms 252 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 380 KB Output is correct
77 Correct 2 ms 256 KB Output is correct
78 Correct 2 ms 256 KB Output is correct
79 Correct 7 ms 888 KB Output is correct
80 Correct 603 ms 16484 KB Output is correct
81 Correct 581 ms 16376 KB Output is correct
82 Correct 560 ms 16536 KB Output is correct
83 Correct 579 ms 16504 KB Output is correct
84 Correct 558 ms 16396 KB Output is correct
85 Correct 611 ms 16360 KB Output is correct
86 Correct 197 ms 6008 KB Output is correct
87 Correct 2 ms 256 KB Output is correct