Submission #398445

# Submission time Handle Problem Language Result Execution time Memory
398445 2021-05-04T09:54:11 Z AKiko Strange Device (APIO19_strange_device) C++17
100 / 100
1954 ms 82608 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ss second
#define ff first
#define pb push_back
#define pii pair<int, int>
#define INF INT64_MAX
#define debug(n) cout << #n << " = " << n << "\n";
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll MOD = 1e9 + 7;

int main() {
    ll n, A, B, T, K;
    cin >> n >> A >> B;
    K = A / __gcd(B + 1, A);
    if(INF / K / B > 0) {
        T = K * B;
    } else {
        T = INF;
    }
    map<ll, ll> m;
    for(int i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        if(r - l + 1 >= T) {
            cout << T << "\n";
            return 0;
        }
        if(r % T < l % T) {
            m[0]++;
            m[r % T + 1]--;
            m[l % T]++;
            m[T]--;
        } else {
            m[l % T]++;
            m[r % T + 1]--;
        }
    }
    ll prev = 0;
    vector<pair<ll, ll> > segments;
    for(auto el : m) {
        prev += el.ss;
        segments.pb({el.ff, prev});
    }

    ll ans = 0;
    for(int i = 0; i < int(segments.size() - 1); i++) {
        if(segments[i].ss > 0){
            ans += segments[i + 1].ff - segments[i].ff;
        }
    }

    cout << ans << "\n";

    return 0;
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 17 ms 1264 KB Output is correct
3 Correct 17 ms 1300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 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 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 18 ms 1332 KB Output is correct
17 Correct 205 ms 8704 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 1052 ms 272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1828 ms 79492 KB Output is correct
3 Correct 1840 ms 79476 KB Output is correct
4 Correct 1860 ms 79568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1828 ms 79492 KB Output is correct
3 Correct 1840 ms 79476 KB Output is correct
4 Correct 1860 ms 79568 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1850 ms 79448 KB Output is correct
7 Correct 1874 ms 79432 KB Output is correct
8 Correct 1814 ms 79520 KB Output is correct
9 Correct 1898 ms 81388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1828 ms 79492 KB Output is correct
3 Correct 1840 ms 79476 KB Output is correct
4 Correct 1860 ms 79568 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 175 ms 8760 KB Output is correct
7 Correct 171 ms 8728 KB Output is correct
8 Correct 175 ms 8744 KB Output is correct
9 Correct 177 ms 8688 KB Output is correct
10 Correct 174 ms 8636 KB Output is correct
11 Correct 177 ms 8756 KB Output is correct
12 Correct 183 ms 8656 KB Output is correct
13 Correct 181 ms 8720 KB Output is correct
14 Correct 179 ms 8696 KB Output is correct
15 Correct 186 ms 8712 KB Output is correct
16 Correct 204 ms 8688 KB Output is correct
17 Correct 198 ms 8744 KB Output is correct
18 Correct 1839 ms 82608 KB Output is correct
19 Correct 1873 ms 82540 KB Output is correct
20 Correct 1879 ms 81456 KB Output is correct
21 Correct 178 ms 8732 KB Output is correct
22 Correct 181 ms 8640 KB Output is correct
23 Correct 464 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 179 ms 8748 KB Output is correct
3 Correct 194 ms 8652 KB Output is correct
4 Correct 1878 ms 79468 KB Output is correct
5 Correct 177 ms 8632 KB Output is correct
6 Correct 182 ms 8712 KB Output is correct
7 Correct 178 ms 8632 KB Output is correct
8 Correct 179 ms 8724 KB Output is correct
9 Correct 177 ms 8752 KB Output is correct
10 Correct 186 ms 8700 KB Output is correct
11 Correct 175 ms 8720 KB Output is correct
12 Correct 178 ms 8616 KB Output is correct
13 Correct 187 ms 8648 KB Output is correct
14 Correct 1899 ms 81280 KB Output is correct
15 Correct 176 ms 8688 KB Output is correct
16 Correct 1835 ms 79468 KB Output is correct
17 Correct 1798 ms 79568 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 17 ms 1264 KB Output is correct
3 Correct 17 ms 1300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 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 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 18 ms 1332 KB Output is correct
17 Correct 205 ms 8704 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 1052 ms 272 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1828 ms 79492 KB Output is correct
31 Correct 1840 ms 79476 KB Output is correct
32 Correct 1860 ms 79568 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1850 ms 79448 KB Output is correct
35 Correct 1874 ms 79432 KB Output is correct
36 Correct 1814 ms 79520 KB Output is correct
37 Correct 1898 ms 81388 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 175 ms 8760 KB Output is correct
40 Correct 171 ms 8728 KB Output is correct
41 Correct 175 ms 8744 KB Output is correct
42 Correct 177 ms 8688 KB Output is correct
43 Correct 174 ms 8636 KB Output is correct
44 Correct 177 ms 8756 KB Output is correct
45 Correct 183 ms 8656 KB Output is correct
46 Correct 181 ms 8720 KB Output is correct
47 Correct 179 ms 8696 KB Output is correct
48 Correct 186 ms 8712 KB Output is correct
49 Correct 204 ms 8688 KB Output is correct
50 Correct 198 ms 8744 KB Output is correct
51 Correct 1839 ms 82608 KB Output is correct
52 Correct 1873 ms 82540 KB Output is correct
53 Correct 1879 ms 81456 KB Output is correct
54 Correct 178 ms 8732 KB Output is correct
55 Correct 181 ms 8640 KB Output is correct
56 Correct 464 ms 204 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 179 ms 8748 KB Output is correct
59 Correct 194 ms 8652 KB Output is correct
60 Correct 1878 ms 79468 KB Output is correct
61 Correct 177 ms 8632 KB Output is correct
62 Correct 182 ms 8712 KB Output is correct
63 Correct 178 ms 8632 KB Output is correct
64 Correct 179 ms 8724 KB Output is correct
65 Correct 177 ms 8752 KB Output is correct
66 Correct 186 ms 8700 KB Output is correct
67 Correct 175 ms 8720 KB Output is correct
68 Correct 178 ms 8616 KB Output is correct
69 Correct 187 ms 8648 KB Output is correct
70 Correct 1899 ms 81280 KB Output is correct
71 Correct 176 ms 8688 KB Output is correct
72 Correct 1835 ms 79468 KB Output is correct
73 Correct 1798 ms 79568 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 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 17 ms 1264 KB Output is correct
80 Correct 1876 ms 79356 KB Output is correct
81 Correct 1836 ms 79452 KB Output is correct
82 Correct 1873 ms 79444 KB Output is correct
83 Correct 1880 ms 79400 KB Output is correct
84 Correct 1954 ms 79692 KB Output is correct
85 Correct 1946 ms 79440 KB Output is correct
86 Correct 471 ms 204 KB Output is correct
87 Correct 1 ms 204 KB Output is correct