Submission #171604

# Submission time Handle Problem Language Result Execution time Memory
171604 2019-12-29T11:18:54 Z rama_pang Strange Device (APIO19_strange_device) C++14
100 / 100
589 ms 17252 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;
    }

    printf("%lld", ans);
    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 376 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 7 ms 888 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 256 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 888 KB Output is correct
17 Correct 59 ms 2936 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 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 425 ms 16168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 504 ms 17252 KB Output is correct
3 Correct 514 ms 16144 KB Output is correct
4 Correct 530 ms 16116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 504 ms 17252 KB Output is correct
3 Correct 514 ms 16144 KB Output is correct
4 Correct 530 ms 16116 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 512 ms 16328 KB Output is correct
7 Correct 508 ms 16248 KB Output is correct
8 Correct 513 ms 16320 KB Output is correct
9 Correct 584 ms 17000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 504 ms 17252 KB Output is correct
3 Correct 514 ms 16144 KB Output is correct
4 Correct 530 ms 16116 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 50 ms 2952 KB Output is correct
7 Correct 60 ms 2936 KB Output is correct
8 Correct 51 ms 2936 KB Output is correct
9 Correct 55 ms 2928 KB Output is correct
10 Correct 51 ms 2936 KB Output is correct
11 Correct 54 ms 2936 KB Output is correct
12 Correct 50 ms 2936 KB Output is correct
13 Correct 58 ms 2964 KB Output is correct
14 Correct 50 ms 2936 KB Output is correct
15 Correct 57 ms 2892 KB Output is correct
16 Correct 56 ms 2936 KB Output is correct
17 Correct 56 ms 2936 KB Output is correct
18 Correct 508 ms 17144 KB Output is correct
19 Correct 495 ms 17148 KB Output is correct
20 Correct 584 ms 17144 KB Output is correct
21 Correct 56 ms 2936 KB Output is correct
22 Correct 51 ms 2936 KB Output is correct
23 Correct 195 ms 6204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 55 ms 2268 KB Output is correct
3 Correct 55 ms 2936 KB Output is correct
4 Correct 576 ms 16376 KB Output is correct
5 Correct 56 ms 2936 KB Output is correct
6 Correct 56 ms 2916 KB Output is correct
7 Correct 56 ms 2936 KB Output is correct
8 Correct 56 ms 2936 KB Output is correct
9 Correct 55 ms 3068 KB Output is correct
10 Correct 55 ms 2936 KB Output is correct
11 Correct 56 ms 2952 KB Output is correct
12 Correct 52 ms 3068 KB Output is correct
13 Correct 56 ms 3076 KB Output is correct
14 Correct 557 ms 17016 KB Output is correct
15 Correct 55 ms 2680 KB Output is correct
16 Correct 502 ms 16632 KB Output is correct
17 Correct 498 ms 16304 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 7 ms 888 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 256 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 888 KB Output is correct
17 Correct 59 ms 2936 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 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 425 ms 16168 KB Output is correct
29 Correct 2 ms 452 KB Output is correct
30 Correct 504 ms 17252 KB Output is correct
31 Correct 514 ms 16144 KB Output is correct
32 Correct 530 ms 16116 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 512 ms 16328 KB Output is correct
35 Correct 508 ms 16248 KB Output is correct
36 Correct 513 ms 16320 KB Output is correct
37 Correct 584 ms 17000 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 50 ms 2952 KB Output is correct
40 Correct 60 ms 2936 KB Output is correct
41 Correct 51 ms 2936 KB Output is correct
42 Correct 55 ms 2928 KB Output is correct
43 Correct 51 ms 2936 KB Output is correct
44 Correct 54 ms 2936 KB Output is correct
45 Correct 50 ms 2936 KB Output is correct
46 Correct 58 ms 2964 KB Output is correct
47 Correct 50 ms 2936 KB Output is correct
48 Correct 57 ms 2892 KB Output is correct
49 Correct 56 ms 2936 KB Output is correct
50 Correct 56 ms 2936 KB Output is correct
51 Correct 508 ms 17144 KB Output is correct
52 Correct 495 ms 17148 KB Output is correct
53 Correct 584 ms 17144 KB Output is correct
54 Correct 56 ms 2936 KB Output is correct
55 Correct 51 ms 2936 KB Output is correct
56 Correct 195 ms 6204 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 55 ms 2268 KB Output is correct
59 Correct 55 ms 2936 KB Output is correct
60 Correct 576 ms 16376 KB Output is correct
61 Correct 56 ms 2936 KB Output is correct
62 Correct 56 ms 2916 KB Output is correct
63 Correct 56 ms 2936 KB Output is correct
64 Correct 56 ms 2936 KB Output is correct
65 Correct 55 ms 3068 KB Output is correct
66 Correct 55 ms 2936 KB Output is correct
67 Correct 56 ms 2952 KB Output is correct
68 Correct 52 ms 3068 KB Output is correct
69 Correct 56 ms 3076 KB Output is correct
70 Correct 557 ms 17016 KB Output is correct
71 Correct 55 ms 2680 KB Output is correct
72 Correct 502 ms 16632 KB Output is correct
73 Correct 498 ms 16304 KB Output is correct
74 Correct 2 ms 252 KB Output is correct
75 Correct 2 ms 256 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 256 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 7 ms 888 KB Output is correct
80 Correct 567 ms 16496 KB Output is correct
81 Correct 568 ms 16508 KB Output is correct
82 Correct 555 ms 16508 KB Output is correct
83 Correct 557 ms 16492 KB Output is correct
84 Correct 561 ms 16476 KB Output is correct
85 Correct 589 ms 16504 KB Output is correct
86 Correct 197 ms 6204 KB Output is correct
87 Correct 2 ms 256 KB Output is correct