Submission #1031821

# Submission time Handle Problem Language Result Execution time Memory
1031821 2024-07-23T07:40:58 Z stdfloat Strange Device (APIO19_strange_device) C++17
100 / 100
607 ms 116832 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n;
    ll A, B;
    cin >> n >> A >> B;

    map<ll, int> m;
    __int128 L = (__int128)A / __gcd(A, B + 1) * B;
    while (n--) {
        ll l, r;
        cin >> l >> r;

        if (L <= r - l + 1) {
            m[0]++; m[L]--;
            continue;
        }

        m[l % L]++; m[r % L + 1]--;

        if (l % L > r % L) {
            m[0]++; m[L]--;
        }
    }

    vector<pair<ll, int>> v;
    for (auto i : m) v.push_back(i);

    int sm = 0;
    ll ans = 0;
    for (int i = 0; i + 1 < (int)v.size(); i++) {
        sm += v[i].second;
        ans += !!sm * (v[i + 1].first - v[i].first);
    }

    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 73 ms 8772 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 142 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 434 ms 79428 KB Output is correct
3 Correct 463 ms 79608 KB Output is correct
4 Correct 490 ms 79404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 434 ms 79428 KB Output is correct
3 Correct 463 ms 79608 KB Output is correct
4 Correct 490 ms 79404 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 429 ms 79448 KB Output is correct
7 Correct 434 ms 79548 KB Output is correct
8 Correct 460 ms 79544 KB Output is correct
9 Correct 531 ms 79452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 434 ms 79428 KB Output is correct
3 Correct 463 ms 79608 KB Output is correct
4 Correct 490 ms 79404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 36 ms 8872 KB Output is correct
7 Correct 33 ms 8904 KB Output is correct
8 Correct 35 ms 8820 KB Output is correct
9 Correct 41 ms 8900 KB Output is correct
10 Correct 39 ms 8844 KB Output is correct
11 Correct 36 ms 8904 KB Output is correct
12 Correct 38 ms 8912 KB Output is correct
13 Correct 38 ms 8912 KB Output is correct
14 Correct 32 ms 8792 KB Output is correct
15 Correct 39 ms 8856 KB Output is correct
16 Correct 41 ms 8900 KB Output is correct
17 Correct 43 ms 8904 KB Output is correct
18 Correct 461 ms 79536 KB Output is correct
19 Correct 483 ms 79544 KB Output is correct
20 Correct 537 ms 79540 KB Output is correct
21 Correct 39 ms 8904 KB Output is correct
22 Correct 41 ms 8900 KB Output is correct
23 Correct 62 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 39 ms 8704 KB Output is correct
3 Correct 42 ms 8688 KB Output is correct
4 Correct 463 ms 79624 KB Output is correct
5 Correct 43 ms 9156 KB Output is correct
6 Correct 43 ms 8912 KB Output is correct
7 Correct 43 ms 8736 KB Output is correct
8 Correct 42 ms 8904 KB Output is correct
9 Correct 42 ms 8892 KB Output is correct
10 Correct 37 ms 8900 KB Output is correct
11 Correct 37 ms 8900 KB Output is correct
12 Correct 37 ms 8900 KB Output is correct
13 Correct 40 ms 8832 KB Output is correct
14 Correct 485 ms 79548 KB Output is correct
15 Correct 54 ms 8900 KB Output is correct
16 Correct 417 ms 79552 KB Output is correct
17 Correct 441 ms 79548 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 73 ms 8772 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 142 ms 428 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 434 ms 79428 KB Output is correct
31 Correct 463 ms 79608 KB Output is correct
32 Correct 490 ms 79404 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 429 ms 79448 KB Output is correct
35 Correct 434 ms 79548 KB Output is correct
36 Correct 460 ms 79544 KB Output is correct
37 Correct 531 ms 79452 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 36 ms 8872 KB Output is correct
40 Correct 33 ms 8904 KB Output is correct
41 Correct 35 ms 8820 KB Output is correct
42 Correct 41 ms 8900 KB Output is correct
43 Correct 39 ms 8844 KB Output is correct
44 Correct 36 ms 8904 KB Output is correct
45 Correct 38 ms 8912 KB Output is correct
46 Correct 38 ms 8912 KB Output is correct
47 Correct 32 ms 8792 KB Output is correct
48 Correct 39 ms 8856 KB Output is correct
49 Correct 41 ms 8900 KB Output is correct
50 Correct 43 ms 8904 KB Output is correct
51 Correct 461 ms 79536 KB Output is correct
52 Correct 483 ms 79544 KB Output is correct
53 Correct 537 ms 79540 KB Output is correct
54 Correct 39 ms 8904 KB Output is correct
55 Correct 41 ms 8900 KB Output is correct
56 Correct 62 ms 428 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 39 ms 8704 KB Output is correct
59 Correct 42 ms 8688 KB Output is correct
60 Correct 463 ms 79624 KB Output is correct
61 Correct 43 ms 9156 KB Output is correct
62 Correct 43 ms 8912 KB Output is correct
63 Correct 43 ms 8736 KB Output is correct
64 Correct 42 ms 8904 KB Output is correct
65 Correct 42 ms 8892 KB Output is correct
66 Correct 37 ms 8900 KB Output is correct
67 Correct 37 ms 8900 KB Output is correct
68 Correct 37 ms 8900 KB Output is correct
69 Correct 40 ms 8832 KB Output is correct
70 Correct 485 ms 79548 KB Output is correct
71 Correct 54 ms 8900 KB Output is correct
72 Correct 417 ms 79552 KB Output is correct
73 Correct 441 ms 79548 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 456 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 4 ms 1740 KB Output is correct
80 Correct 540 ms 116628 KB Output is correct
81 Correct 518 ms 116720 KB Output is correct
82 Correct 595 ms 116624 KB Output is correct
83 Correct 607 ms 116616 KB Output is correct
84 Correct 582 ms 116768 KB Output is correct
85 Correct 552 ms 116832 KB Output is correct
86 Correct 74 ms 13116 KB Output is correct
87 Correct 0 ms 344 KB Output is correct