Submission #559786

# Submission time Handle Problem Language Result Execution time Memory
559786 2022-05-10T15:21:11 Z tranxuanbach Strange Device (APIO19_strange_device) C++17
100 / 100
867 ms 100184 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define Fora(v, a) for (auto v: (a))
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)(a).size())

using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;

const int N = 1e6 + 5;

int n; ll A, B;

ll ans;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("KEK.inp", "r", stdin);
    // freopen("KEK.out", "w", stdout);
    cin >> n >> A >> B;
    __int128 G = (__int128)(A / __gcd(A, B + 1)) * B;
    if (G > (__int128)1e18){
        map <ll, ll> mpp;
        while (n--){
            ll l, r; cin >> l >> r;
            mpp[l]++; mpp[r + 1]--;
        }
        int cnt = 0; ll l = 0;
        Fora(elem, mpp){
            ll r = elem.fi;
            if (cnt != 0){
                ans += r - l;
            }
            cnt += elem.se;
            l = r;
        }
        cout << ans << endl;
        return 0;
    }
    ll g = G;
    map <ll, ll> mpp;
    while (n--){
        ll l, r; cin >> l >> r;
        if (r - l + 1 >= g){
            cout << g << endl;
            return 0;
        }
        l %= g; r %= g;
        if (l <= r){
            mpp[l]++; mpp[r + 1]--;
        }
        else{
            mpp[l]++; mpp[g]--; mpp[0]++; mpp[r + 1]--;
        }
    }

    int cnt = 0; ll l = 0;
    Fora(elem, mpp){
        ll r = elem.fi;
        if (cnt != 0){
            ans += r - l;
        }
        cnt += elem.se;
        l = r;
    }
    cout << ans << endl;
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 7 ms 1232 KB Output is correct
3 Correct 6 ms 1304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1236 KB Output is correct
17 Correct 65 ms 10324 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 281 ms 25372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 706 ms 72096 KB Output is correct
3 Correct 711 ms 76160 KB Output is correct
4 Correct 867 ms 100024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 706 ms 72096 KB Output is correct
3 Correct 711 ms 76160 KB Output is correct
4 Correct 867 ms 100024 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 743 ms 100104 KB Output is correct
7 Correct 713 ms 100132 KB Output is correct
8 Correct 702 ms 100020 KB Output is correct
9 Correct 777 ms 99972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 706 ms 72096 KB Output is correct
3 Correct 711 ms 76160 KB Output is correct
4 Correct 867 ms 100024 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 57 ms 10176 KB Output is correct
7 Correct 58 ms 10268 KB Output is correct
8 Correct 60 ms 10176 KB Output is correct
9 Correct 72 ms 10204 KB Output is correct
10 Correct 74 ms 10192 KB Output is correct
11 Correct 59 ms 10276 KB Output is correct
12 Correct 57 ms 10288 KB Output is correct
13 Correct 67 ms 10188 KB Output is correct
14 Correct 63 ms 10264 KB Output is correct
15 Correct 73 ms 10292 KB Output is correct
16 Correct 71 ms 10276 KB Output is correct
17 Correct 65 ms 10360 KB Output is correct
18 Correct 710 ms 100076 KB Output is correct
19 Correct 751 ms 99996 KB Output is correct
20 Correct 772 ms 100060 KB Output is correct
21 Correct 61 ms 10264 KB Output is correct
22 Correct 59 ms 10284 KB Output is correct
23 Correct 132 ms 12824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 75 ms 10204 KB Output is correct
3 Correct 73 ms 10220 KB Output is correct
4 Correct 730 ms 76232 KB Output is correct
5 Correct 74 ms 10252 KB Output is correct
6 Correct 74 ms 10188 KB Output is correct
7 Correct 89 ms 10216 KB Output is correct
8 Correct 82 ms 10188 KB Output is correct
9 Correct 69 ms 10276 KB Output is correct
10 Correct 65 ms 10256 KB Output is correct
11 Correct 66 ms 10240 KB Output is correct
12 Correct 68 ms 10248 KB Output is correct
13 Correct 72 ms 10272 KB Output is correct
14 Correct 833 ms 100184 KB Output is correct
15 Correct 63 ms 10240 KB Output is correct
16 Correct 716 ms 100064 KB Output is correct
17 Correct 718 ms 99952 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 7 ms 1232 KB Output is correct
3 Correct 6 ms 1304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1236 KB Output is correct
17 Correct 65 ms 10324 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 281 ms 25372 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 706 ms 72096 KB Output is correct
31 Correct 711 ms 76160 KB Output is correct
32 Correct 867 ms 100024 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 743 ms 100104 KB Output is correct
35 Correct 713 ms 100132 KB Output is correct
36 Correct 702 ms 100020 KB Output is correct
37 Correct 777 ms 99972 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 57 ms 10176 KB Output is correct
40 Correct 58 ms 10268 KB Output is correct
41 Correct 60 ms 10176 KB Output is correct
42 Correct 72 ms 10204 KB Output is correct
43 Correct 74 ms 10192 KB Output is correct
44 Correct 59 ms 10276 KB Output is correct
45 Correct 57 ms 10288 KB Output is correct
46 Correct 67 ms 10188 KB Output is correct
47 Correct 63 ms 10264 KB Output is correct
48 Correct 73 ms 10292 KB Output is correct
49 Correct 71 ms 10276 KB Output is correct
50 Correct 65 ms 10360 KB Output is correct
51 Correct 710 ms 100076 KB Output is correct
52 Correct 751 ms 99996 KB Output is correct
53 Correct 772 ms 100060 KB Output is correct
54 Correct 61 ms 10264 KB Output is correct
55 Correct 59 ms 10284 KB Output is correct
56 Correct 132 ms 12824 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 75 ms 10204 KB Output is correct
59 Correct 73 ms 10220 KB Output is correct
60 Correct 730 ms 76232 KB Output is correct
61 Correct 74 ms 10252 KB Output is correct
62 Correct 74 ms 10188 KB Output is correct
63 Correct 89 ms 10216 KB Output is correct
64 Correct 82 ms 10188 KB Output is correct
65 Correct 69 ms 10276 KB Output is correct
66 Correct 65 ms 10256 KB Output is correct
67 Correct 66 ms 10240 KB Output is correct
68 Correct 68 ms 10248 KB Output is correct
69 Correct 72 ms 10272 KB Output is correct
70 Correct 833 ms 100184 KB Output is correct
71 Correct 63 ms 10240 KB Output is correct
72 Correct 716 ms 100064 KB Output is correct
73 Correct 718 ms 99952 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 320 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 7 ms 1232 KB Output is correct
80 Correct 771 ms 100072 KB Output is correct
81 Correct 770 ms 100104 KB Output is correct
82 Correct 826 ms 100040 KB Output is correct
83 Correct 842 ms 100032 KB Output is correct
84 Correct 805 ms 100020 KB Output is correct
85 Correct 843 ms 99992 KB Output is correct
86 Correct 136 ms 12828 KB Output is correct
87 Correct 1 ms 212 KB Output is correct