Submission #1015236

# Submission time Handle Problem Language Result Execution time Memory
1015236 2024-07-06T07:47:46 Z aufan Strange Device (APIO19_strange_device) C++17
100 / 100
669 ms 100344 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int INFF = 2e18;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int n, a, b;
        cin >> n >> a >> b;

        int len = lcm(a, b + 1) / (b + 1) * b;

        set<pair<int, int>> seg;
        
        auto insert = [&](int l, int r) {
                auto it = seg.lower_bound({l, 0});
                if (!seg.empty() && it != seg.begin()) --it;

                int mnl = l, mxr = r;
                vector<pair<int, int>> del;

                for (; it != seg.end(); it++) {
                        if (it->fi > r) break;

                        if (it->fi < l && it->se >= l) {
                                del.push_back(*it);
                                mnl = min(mnl, it->fi);
                                mxr = max(mxr, it->se);
                        }

                        if (it->fi >= l && it->fi <= r) {
                                del.push_back(*it);
                                mnl = min(mnl, it->fi);
                                mxr = max(mxr, it->se);
                        }
                }

                for (auto p : del) seg.erase(p);

                seg.insert({mnl, mxr});
        };

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

                if (a <= INFF / b && r - l + 1 >= len) {
                        cout << len << '\n';
                        return 0;
                }
                
                if (a <= INFF / b) {
                        l %= len;
                        r %= len;
                }

                if (l <= r) {
                        insert(l, r);
                } else {
                        assert(a <= INFF / b);

                        insert(l, len - 1);
                        insert(0, r);
                }
        }
        
        int ans = 0;
        for (auto [l, r] : seg) ans += r - l + 1;

        cout << ans << '\n';

        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 4 ms 1360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 51 ms 10348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 200 ms 25524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 495 ms 100112 KB Output is correct
3 Correct 517 ms 100224 KB Output is correct
4 Correct 600 ms 100344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 495 ms 100112 KB Output is correct
3 Correct 517 ms 100224 KB Output is correct
4 Correct 600 ms 100344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 547 ms 100068 KB Output is correct
7 Correct 550 ms 100200 KB Output is correct
8 Correct 541 ms 100072 KB Output is correct
9 Correct 562 ms 100088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 495 ms 100112 KB Output is correct
3 Correct 517 ms 100224 KB Output is correct
4 Correct 600 ms 100344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 40 ms 10380 KB Output is correct
7 Correct 44 ms 10356 KB Output is correct
8 Correct 42 ms 10340 KB Output is correct
9 Correct 46 ms 10324 KB Output is correct
10 Correct 39 ms 10352 KB Output is correct
11 Correct 39 ms 10324 KB Output is correct
12 Correct 44 ms 10284 KB Output is correct
13 Correct 46 ms 10320 KB Output is correct
14 Correct 42 ms 10320 KB Output is correct
15 Correct 53 ms 10328 KB Output is correct
16 Correct 53 ms 10380 KB Output is correct
17 Correct 47 ms 10276 KB Output is correct
18 Correct 498 ms 100180 KB Output is correct
19 Correct 520 ms 100148 KB Output is correct
20 Correct 555 ms 100176 KB Output is correct
21 Correct 57 ms 10376 KB Output is correct
22 Correct 45 ms 10324 KB Output is correct
23 Correct 93 ms 12980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 48 ms 10200 KB Output is correct
3 Correct 57 ms 10192 KB Output is correct
4 Correct 567 ms 100160 KB Output is correct
5 Correct 58 ms 10264 KB Output is correct
6 Correct 65 ms 10320 KB Output is correct
7 Correct 61 ms 10364 KB Output is correct
8 Correct 56 ms 10324 KB Output is correct
9 Correct 49 ms 10304 KB Output is correct
10 Correct 42 ms 10320 KB Output is correct
11 Correct 55 ms 10320 KB Output is correct
12 Correct 46 ms 10320 KB Output is correct
13 Correct 49 ms 10188 KB Output is correct
14 Correct 620 ms 100076 KB Output is correct
15 Correct 47 ms 9748 KB Output is correct
16 Correct 463 ms 100072 KB Output is correct
17 Correct 441 ms 100084 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 4 ms 1360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 51 ms 10348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 200 ms 25524 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 495 ms 100112 KB Output is correct
31 Correct 517 ms 100224 KB Output is correct
32 Correct 600 ms 100344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 547 ms 100068 KB Output is correct
35 Correct 550 ms 100200 KB Output is correct
36 Correct 541 ms 100072 KB Output is correct
37 Correct 562 ms 100088 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 40 ms 10380 KB Output is correct
40 Correct 44 ms 10356 KB Output is correct
41 Correct 42 ms 10340 KB Output is correct
42 Correct 46 ms 10324 KB Output is correct
43 Correct 39 ms 10352 KB Output is correct
44 Correct 39 ms 10324 KB Output is correct
45 Correct 44 ms 10284 KB Output is correct
46 Correct 46 ms 10320 KB Output is correct
47 Correct 42 ms 10320 KB Output is correct
48 Correct 53 ms 10328 KB Output is correct
49 Correct 53 ms 10380 KB Output is correct
50 Correct 47 ms 10276 KB Output is correct
51 Correct 498 ms 100180 KB Output is correct
52 Correct 520 ms 100148 KB Output is correct
53 Correct 555 ms 100176 KB Output is correct
54 Correct 57 ms 10376 KB Output is correct
55 Correct 45 ms 10324 KB Output is correct
56 Correct 93 ms 12980 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 48 ms 10200 KB Output is correct
59 Correct 57 ms 10192 KB Output is correct
60 Correct 567 ms 100160 KB Output is correct
61 Correct 58 ms 10264 KB Output is correct
62 Correct 65 ms 10320 KB Output is correct
63 Correct 61 ms 10364 KB Output is correct
64 Correct 56 ms 10324 KB Output is correct
65 Correct 49 ms 10304 KB Output is correct
66 Correct 42 ms 10320 KB Output is correct
67 Correct 55 ms 10320 KB Output is correct
68 Correct 46 ms 10320 KB Output is correct
69 Correct 49 ms 10188 KB Output is correct
70 Correct 620 ms 100076 KB Output is correct
71 Correct 47 ms 9748 KB Output is correct
72 Correct 463 ms 100072 KB Output is correct
73 Correct 441 ms 100084 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 344 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 6 ms 1372 KB Output is correct
80 Correct 568 ms 100076 KB Output is correct
81 Correct 542 ms 100180 KB Output is correct
82 Correct 611 ms 100128 KB Output is correct
83 Correct 584 ms 100080 KB Output is correct
84 Correct 669 ms 100028 KB Output is correct
85 Correct 560 ms 100180 KB Output is correct
86 Correct 100 ms 13096 KB Output is correct
87 Correct 0 ms 348 KB Output is correct