Submission #465484

# Submission time Handle Problem Language Result Execution time Memory
465484 2021-08-16T08:28:19 Z alextodoran Strange Device (APIO19_strange_device) C++17
100 / 100
1088 ms 100156 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll INF = LLONG_MAX / 2;

ll gcd (const ll &a, const ll &b)
{
    if(b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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

    ll per = A / gcd(B + 1, A);
    if(INF / per < B)
        per = INF;
    else
        per *= B;

    map <ll, int> mars;

    function <void (ll, ll)> proc = [&] (ll l, ll r)
    {
        if(r - l + 1 >= per)
            mars[0]++;
        else
        {
            l %= per;
            r %= per;
            if(l <= r)
            {
                mars[l]++;
                mars[r + 1]--;
            }
            else
            {
                mars[l]++;
                mars[per]--;

                mars[0]++;
                mars[r + 1]--;
            }
        }
    };

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

        proc(l, r);
    }

    mars[per] = 0;

    ll answer = 0;
    int sum = 0;
    ll pr = 0;

    for(pair <ll, int> x : mars)
    {
        if(sum > 0)
            answer += x.first - pr;
        sum += x.second;
        pr = x.first;
    }

    cout << answer << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 8 ms 1228 KB Output is correct
3 Correct 10 ms 1224 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 1264 KB Output is correct
17 Correct 78 ms 10292 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 317 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 801 ms 63100 KB Output is correct
3 Correct 800 ms 63092 KB Output is correct
4 Correct 850 ms 63124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 801 ms 63100 KB Output is correct
3 Correct 800 ms 63092 KB Output is correct
4 Correct 850 ms 63124 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 803 ms 63104 KB Output is correct
7 Correct 823 ms 63136 KB Output is correct
8 Correct 842 ms 63208 KB Output is correct
9 Correct 966 ms 63272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 801 ms 63100 KB Output is correct
3 Correct 800 ms 63092 KB Output is correct
4 Correct 850 ms 63124 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 81 ms 9984 KB Output is correct
7 Correct 75 ms 10004 KB Output is correct
8 Correct 83 ms 10040 KB Output is correct
9 Correct 78 ms 10052 KB Output is correct
10 Correct 74 ms 9976 KB Output is correct
11 Correct 76 ms 10076 KB Output is correct
12 Correct 75 ms 10052 KB Output is correct
13 Correct 78 ms 10016 KB Output is correct
14 Correct 71 ms 10052 KB Output is correct
15 Correct 84 ms 10052 KB Output is correct
16 Correct 87 ms 9988 KB Output is correct
17 Correct 79 ms 10028 KB Output is correct
18 Correct 796 ms 63132 KB Output is correct
19 Correct 980 ms 63072 KB Output is correct
20 Correct 895 ms 63104 KB Output is correct
21 Correct 79 ms 9096 KB Output is correct
22 Correct 83 ms 9028 KB Output is correct
23 Correct 138 ms 2844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 85 ms 9188 KB Output is correct
3 Correct 79 ms 9052 KB Output is correct
4 Correct 895 ms 63108 KB Output is correct
5 Correct 85 ms 8772 KB Output is correct
6 Correct 79 ms 8704 KB Output is correct
7 Correct 82 ms 8808 KB Output is correct
8 Correct 78 ms 8808 KB Output is correct
9 Correct 78 ms 8768 KB Output is correct
10 Correct 75 ms 8824 KB Output is correct
11 Correct 80 ms 8840 KB Output is correct
12 Correct 75 ms 8796 KB Output is correct
13 Correct 83 ms 8752 KB Output is correct
14 Correct 1088 ms 63188 KB Output is correct
15 Correct 71 ms 8388 KB Output is correct
16 Correct 796 ms 63152 KB Output is correct
17 Correct 790 ms 63028 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 8 ms 1228 KB Output is correct
3 Correct 10 ms 1224 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 1264 KB Output is correct
17 Correct 78 ms 10292 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 316 KB Output is correct
22 Correct 1 ms 216 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 448 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 317 ms 424 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 801 ms 63100 KB Output is correct
31 Correct 800 ms 63092 KB Output is correct
32 Correct 850 ms 63124 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 803 ms 63104 KB Output is correct
35 Correct 823 ms 63136 KB Output is correct
36 Correct 842 ms 63208 KB Output is correct
37 Correct 966 ms 63272 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 81 ms 9984 KB Output is correct
40 Correct 75 ms 10004 KB Output is correct
41 Correct 83 ms 10040 KB Output is correct
42 Correct 78 ms 10052 KB Output is correct
43 Correct 74 ms 9976 KB Output is correct
44 Correct 76 ms 10076 KB Output is correct
45 Correct 75 ms 10052 KB Output is correct
46 Correct 78 ms 10016 KB Output is correct
47 Correct 71 ms 10052 KB Output is correct
48 Correct 84 ms 10052 KB Output is correct
49 Correct 87 ms 9988 KB Output is correct
50 Correct 79 ms 10028 KB Output is correct
51 Correct 796 ms 63132 KB Output is correct
52 Correct 980 ms 63072 KB Output is correct
53 Correct 895 ms 63104 KB Output is correct
54 Correct 79 ms 9096 KB Output is correct
55 Correct 83 ms 9028 KB Output is correct
56 Correct 138 ms 2844 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 85 ms 9188 KB Output is correct
59 Correct 79 ms 9052 KB Output is correct
60 Correct 895 ms 63108 KB Output is correct
61 Correct 85 ms 8772 KB Output is correct
62 Correct 79 ms 8704 KB Output is correct
63 Correct 82 ms 8808 KB Output is correct
64 Correct 78 ms 8808 KB Output is correct
65 Correct 78 ms 8768 KB Output is correct
66 Correct 75 ms 8824 KB Output is correct
67 Correct 80 ms 8840 KB Output is correct
68 Correct 75 ms 8796 KB Output is correct
69 Correct 83 ms 8752 KB Output is correct
70 Correct 1088 ms 63188 KB Output is correct
71 Correct 71 ms 8388 KB Output is correct
72 Correct 796 ms 63152 KB Output is correct
73 Correct 790 ms 63028 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 0 ms 316 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 8 ms 1228 KB Output is correct
80 Correct 985 ms 100056 KB Output is correct
81 Correct 984 ms 100108 KB Output is correct
82 Correct 928 ms 100004 KB Output is correct
83 Correct 910 ms 100140 KB Output is correct
84 Correct 918 ms 100084 KB Output is correct
85 Correct 870 ms 100156 KB Output is correct
86 Correct 138 ms 12744 KB Output is correct
87 Correct 1 ms 204 KB Output is correct