Submission #721639

# Submission time Handle Problem Language Result Execution time Memory
721639 2023-04-11T06:02:04 Z GrandTiger1729 Strange Device (APIO19_strange_device) C++17
100 / 100
654 ms 38604 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18 + 10;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;
    long long A, B; cin >> A >> B;
    if ((__int128_t)1 * A * B / __gcd(A, B + 1) >= INF){
        long long ans = 0;
        for (int i = 0; i < n; i++){
            long long l, r; cin >> l >> r;
            ans += r - l + 1;
        }
        cout << ans << '\n';
        return 0;
    }
    long long D = (__int128_t)1 * A * B / __gcd(A, B + 1);
    vector<pair<long long, int>> res;
    for (int i = 0; i < n; i++){
        long long l, r; cin >> l >> r;
        r++;
        if (r - l >= D){
            cout << D << '\n';
            return 0;
        }
        long long ll = D * (l / D + 1), rr = D * (r / D);
        if (ll > rr){
            res.emplace_back(l % D, 1);
            res.emplace_back(r % D, -1);
        }else{
            res.emplace_back(l % D, 1);
            res.emplace_back(D, -1);
            res.emplace_back(0, 1);
            res.emplace_back(r % D, -1);
        }
    } 
    sort(res.begin(), res.end());
    // cerr << D << '\n';
    // cerr << res.size() << '\n';
    // for (auto &[t, d]: res)
    //     cerr << t << ' ' << d << endl;
    int N = res.size(), cur = 0;
    long long ans = 0;
    for (int i = 0; i < N; ){
        int r = i;
        while (r < N && res[i].first == res[r].first) r++;
        for (int j = i; j < r; j++)
            cur += res[j].second;
        if (cur > 0)
            ans += res[r].first - res[i].first;
        i = r;
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 5 ms 856 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 980 KB Output is correct
17 Correct 60 ms 4548 KB Output is correct
18 Correct 0 ms 212 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 328 ms 33224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 495 ms 33192 KB Output is correct
3 Correct 501 ms 33188 KB Output is correct
4 Correct 460 ms 33256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 495 ms 33192 KB Output is correct
3 Correct 501 ms 33188 KB Output is correct
4 Correct 460 ms 33256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 518 ms 33288 KB Output is correct
7 Correct 474 ms 33296 KB Output is correct
8 Correct 460 ms 33292 KB Output is correct
9 Correct 576 ms 33176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 495 ms 33192 KB Output is correct
3 Correct 501 ms 33188 KB Output is correct
4 Correct 460 ms 33256 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 47 ms 4468 KB Output is correct
7 Correct 51 ms 4468 KB Output is correct
8 Correct 46 ms 4468 KB Output is correct
9 Correct 48 ms 4544 KB Output is correct
10 Correct 46 ms 4556 KB Output is correct
11 Correct 54 ms 4468 KB Output is correct
12 Correct 44 ms 4556 KB Output is correct
13 Correct 55 ms 4448 KB Output is correct
14 Correct 52 ms 4544 KB Output is correct
15 Correct 59 ms 4500 KB Output is correct
16 Correct 56 ms 5188 KB Output is correct
17 Correct 47 ms 5184 KB Output is correct
18 Correct 561 ms 38604 KB Output is correct
19 Correct 491 ms 38516 KB Output is correct
20 Correct 629 ms 38384 KB Output is correct
21 Correct 55 ms 5188 KB Output is correct
22 Correct 44 ms 5180 KB Output is correct
23 Correct 148 ms 17392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 4548 KB Output is correct
3 Correct 66 ms 4572 KB Output is correct
4 Correct 627 ms 33220 KB Output is correct
5 Correct 53 ms 4548 KB Output is correct
6 Correct 52 ms 4488 KB Output is correct
7 Correct 49 ms 4500 KB Output is correct
8 Correct 54 ms 4556 KB Output is correct
9 Correct 53 ms 4552 KB Output is correct
10 Correct 55 ms 4520 KB Output is correct
11 Correct 49 ms 4544 KB Output is correct
12 Correct 45 ms 4548 KB Output is correct
13 Correct 53 ms 4504 KB Output is correct
14 Correct 580 ms 33160 KB Output is correct
15 Correct 54 ms 4556 KB Output is correct
16 Correct 476 ms 34552 KB Output is correct
17 Correct 474 ms 34700 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 5 ms 856 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 980 KB Output is correct
17 Correct 60 ms 4548 KB Output is correct
18 Correct 0 ms 212 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 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 328 ms 33224 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 495 ms 33192 KB Output is correct
31 Correct 501 ms 33188 KB Output is correct
32 Correct 460 ms 33256 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 518 ms 33288 KB Output is correct
35 Correct 474 ms 33296 KB Output is correct
36 Correct 460 ms 33292 KB Output is correct
37 Correct 576 ms 33176 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 47 ms 4468 KB Output is correct
40 Correct 51 ms 4468 KB Output is correct
41 Correct 46 ms 4468 KB Output is correct
42 Correct 48 ms 4544 KB Output is correct
43 Correct 46 ms 4556 KB Output is correct
44 Correct 54 ms 4468 KB Output is correct
45 Correct 44 ms 4556 KB Output is correct
46 Correct 55 ms 4448 KB Output is correct
47 Correct 52 ms 4544 KB Output is correct
48 Correct 59 ms 4500 KB Output is correct
49 Correct 56 ms 5188 KB Output is correct
50 Correct 47 ms 5184 KB Output is correct
51 Correct 561 ms 38604 KB Output is correct
52 Correct 491 ms 38516 KB Output is correct
53 Correct 629 ms 38384 KB Output is correct
54 Correct 55 ms 5188 KB Output is correct
55 Correct 44 ms 5180 KB Output is correct
56 Correct 148 ms 17392 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 53 ms 4548 KB Output is correct
59 Correct 66 ms 4572 KB Output is correct
60 Correct 627 ms 33220 KB Output is correct
61 Correct 53 ms 4548 KB Output is correct
62 Correct 52 ms 4488 KB Output is correct
63 Correct 49 ms 4500 KB Output is correct
64 Correct 54 ms 4556 KB Output is correct
65 Correct 53 ms 4552 KB Output is correct
66 Correct 55 ms 4520 KB Output is correct
67 Correct 49 ms 4544 KB Output is correct
68 Correct 45 ms 4548 KB Output is correct
69 Correct 53 ms 4504 KB Output is correct
70 Correct 580 ms 33160 KB Output is correct
71 Correct 54 ms 4556 KB Output is correct
72 Correct 476 ms 34552 KB Output is correct
73 Correct 474 ms 34700 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 320 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 5 ms 1348 KB Output is correct
80 Correct 654 ms 34476 KB Output is correct
81 Correct 613 ms 34604 KB Output is correct
82 Correct 575 ms 34456 KB Output is correct
83 Correct 595 ms 34472 KB Output is correct
84 Correct 579 ms 34396 KB Output is correct
85 Correct 575 ms 34480 KB Output is correct
86 Correct 151 ms 22544 KB Output is correct
87 Correct 1 ms 320 KB Output is correct