Submission #678090

# Submission time Handle Problem Language Result Execution time Memory
678090 2023-01-05T07:35:17 Z FedShat Strange Device (APIO19_strange_device) C++17
100 / 100
712 ms 83456 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using i128 = __int128;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll INFLL = numeric_limits<ll>::max() / 2;

template<class T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) {
        is >> i;
    }
    return is;
}

#ifdef __APPLE__
#include "../../debug.h"
#else
#define debug(...) 42
#endif

int main() {
    cin.tie(0)->sync_with_stdio(0);
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
#endif
    int n;
    ll a, b;
    cin >> n >> a >> b;
    vector<pair<ll, ll>> lr;
    i128 len = ((i128) a * (i128) b) / gcd(a, b + 1);
    for (int i = 0; i < n; ++i) {
        ll l, r;
        cin >> l >> r;
        if (l == r) {
            lr.push_back({l % len, r % len});
            continue;
        }
        if (r - l + 1 >= len) {
            lr.push_back({0, len - 1});
            continue;
        }
        l %= len;
        r %= len;
        if (l < r) {
            lr.push_back({l, r});
        } else {
            lr.push_back({l, len - 1});
            lr.push_back({0, r});
        }
    }
    vector<pair<ll, int>> segs;
    for (auto [l, r] : lr) {
        segs.push_back({l, 1});
        segs.push_back({r + 1, -1});
    }
    sort(segs.begin(), segs.end(), [&](const pair<ll, int> &a, const pair<ll, int> &b) {
        return a.first < b.first || (a.first == b.first && a.second > b.second);
    });
    ll ans = 0;
    {
        int balance = 0, curl = 0, curr = 0;
        for (auto [x, t] : segs) {
            balance += t;
            if (balance == 0) {
                ans += segs[curr].first - segs[curl].first;
                curl = curr + 1;
            }
            ++curr;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1484 KB Output is correct
3 Correct 7 ms 1392 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 320 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 5 ms 1416 KB Output is correct
17 Correct 57 ms 9800 KB Output is correct
18 Correct 0 ms 312 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 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 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 2 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 355 ms 50404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 534 ms 68908 KB Output is correct
3 Correct 642 ms 66868 KB Output is correct
4 Correct 530 ms 82724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 534 ms 68908 KB Output is correct
3 Correct 642 ms 66868 KB Output is correct
4 Correct 530 ms 82724 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 504 ms 82504 KB Output is correct
7 Correct 506 ms 83456 KB Output is correct
8 Correct 519 ms 82576 KB Output is correct
9 Correct 611 ms 62148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 534 ms 68908 KB Output is correct
3 Correct 642 ms 66868 KB Output is correct
4 Correct 530 ms 82724 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 48 ms 9736 KB Output is correct
7 Correct 52 ms 9800 KB Output is correct
8 Correct 47 ms 9748 KB Output is correct
9 Correct 52 ms 9936 KB Output is correct
10 Correct 47 ms 9748 KB Output is correct
11 Correct 49 ms 9760 KB Output is correct
12 Correct 47 ms 9864 KB Output is correct
13 Correct 55 ms 9820 KB Output is correct
14 Correct 50 ms 9784 KB Output is correct
15 Correct 56 ms 9860 KB Output is correct
16 Correct 54 ms 9760 KB Output is correct
17 Correct 47 ms 9800 KB Output is correct
18 Correct 519 ms 58568 KB Output is correct
19 Correct 507 ms 80244 KB Output is correct
20 Correct 612 ms 58128 KB Output is correct
21 Correct 66 ms 9760 KB Output is correct
22 Correct 45 ms 9740 KB Output is correct
23 Correct 149 ms 34800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 58 ms 9840 KB Output is correct
3 Correct 62 ms 9740 KB Output is correct
4 Correct 634 ms 58280 KB Output is correct
5 Correct 59 ms 9800 KB Output is correct
6 Correct 57 ms 9916 KB Output is correct
7 Correct 54 ms 9852 KB Output is correct
8 Correct 60 ms 9748 KB Output is correct
9 Correct 64 ms 9760 KB Output is correct
10 Correct 57 ms 9772 KB Output is correct
11 Correct 56 ms 9728 KB Output is correct
12 Correct 48 ms 9752 KB Output is correct
13 Correct 55 ms 9800 KB Output is correct
14 Correct 610 ms 61740 KB Output is correct
15 Correct 59 ms 9796 KB Output is correct
16 Correct 476 ms 58540 KB Output is correct
17 Correct 508 ms 58528 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1484 KB Output is correct
3 Correct 7 ms 1392 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 320 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 5 ms 1416 KB Output is correct
17 Correct 57 ms 9800 KB Output is correct
18 Correct 0 ms 312 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 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 355 ms 50404 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 534 ms 68908 KB Output is correct
31 Correct 642 ms 66868 KB Output is correct
32 Correct 530 ms 82724 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 504 ms 82504 KB Output is correct
35 Correct 506 ms 83456 KB Output is correct
36 Correct 519 ms 82576 KB Output is correct
37 Correct 611 ms 62148 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 48 ms 9736 KB Output is correct
40 Correct 52 ms 9800 KB Output is correct
41 Correct 47 ms 9748 KB Output is correct
42 Correct 52 ms 9936 KB Output is correct
43 Correct 47 ms 9748 KB Output is correct
44 Correct 49 ms 9760 KB Output is correct
45 Correct 47 ms 9864 KB Output is correct
46 Correct 55 ms 9820 KB Output is correct
47 Correct 50 ms 9784 KB Output is correct
48 Correct 56 ms 9860 KB Output is correct
49 Correct 54 ms 9760 KB Output is correct
50 Correct 47 ms 9800 KB Output is correct
51 Correct 519 ms 58568 KB Output is correct
52 Correct 507 ms 80244 KB Output is correct
53 Correct 612 ms 58128 KB Output is correct
54 Correct 66 ms 9760 KB Output is correct
55 Correct 45 ms 9740 KB Output is correct
56 Correct 149 ms 34800 KB Output is correct
57 Correct 1 ms 320 KB Output is correct
58 Correct 58 ms 9840 KB Output is correct
59 Correct 62 ms 9740 KB Output is correct
60 Correct 634 ms 58280 KB Output is correct
61 Correct 59 ms 9800 KB Output is correct
62 Correct 57 ms 9916 KB Output is correct
63 Correct 54 ms 9852 KB Output is correct
64 Correct 60 ms 9748 KB Output is correct
65 Correct 64 ms 9760 KB Output is correct
66 Correct 57 ms 9772 KB Output is correct
67 Correct 56 ms 9728 KB Output is correct
68 Correct 48 ms 9752 KB Output is correct
69 Correct 55 ms 9800 KB Output is correct
70 Correct 610 ms 61740 KB Output is correct
71 Correct 59 ms 9796 KB Output is correct
72 Correct 476 ms 58540 KB Output is correct
73 Correct 508 ms 58528 KB Output is correct
74 Correct 1 ms 368 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 316 KB Output is correct
77 Correct 0 ms 320 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 8 ms 1492 KB Output is correct
80 Correct 662 ms 61992 KB Output is correct
81 Correct 645 ms 58456 KB Output is correct
82 Correct 608 ms 58904 KB Output is correct
83 Correct 690 ms 60456 KB Output is correct
84 Correct 712 ms 61328 KB Output is correct
85 Correct 669 ms 61448 KB Output is correct
86 Correct 178 ms 34612 KB Output is correct
87 Correct 1 ms 212 KB Output is correct