Submission #1044889

# Submission time Handle Problem Language Result Execution time Memory
1044889 2024-08-05T14:20:24 Z serifefedartar Strange Device (APIO19_strange_device) C++17
100 / 100
444 ms 74800 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 3e4 + 100;

#define int long long
set<pair<int,int>> st;
void add_seg(int l, int r) {
    st.insert({l, r});
}

signed main() {
    fast
    ll n, A, B, mx = -1;
    cin >> n >> A >> B;

    A = 1e18 / A < B ? 1e18 : A / __gcd(A, B+1) * B;

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

        if (r - l + 1 >= A) {
            cout << A << "\n";
            control = false;
        }

        int x = l % A;
        int y = r % A;
        if (y < x) {
            add_seg(x, A-1);
            add_seg(0, y);
        } else
            add_seg(x, y);
    }

    if (!control)
        return 0;

    ll ans = 0;
    for (auto u : st) {
        ans += max(0LL, u.s - max(mx + 1, u.f) + 1);
        mx = max(mx, u.s);
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 1056 KB Output is correct
3 Correct 3 ms 936 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 384 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 0 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 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 34 ms 6688 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 126 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 340 ms 62880 KB Output is correct
3 Correct 375 ms 63060 KB Output is correct
4 Correct 402 ms 74656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 340 ms 62880 KB Output is correct
3 Correct 375 ms 63060 KB Output is correct
4 Correct 402 ms 74656 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 365 ms 74800 KB Output is correct
7 Correct 378 ms 74340 KB Output is correct
8 Correct 380 ms 74436 KB Output is correct
9 Correct 377 ms 74488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 340 ms 62880 KB Output is correct
3 Correct 375 ms 63060 KB Output is correct
4 Correct 402 ms 74656 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 29 ms 8284 KB Output is correct
7 Correct 29 ms 8332 KB Output is correct
8 Correct 35 ms 8292 KB Output is correct
9 Correct 33 ms 8272 KB Output is correct
10 Correct 31 ms 8332 KB Output is correct
11 Correct 33 ms 8532 KB Output is correct
12 Correct 30 ms 8376 KB Output is correct
13 Correct 34 ms 8388 KB Output is correct
14 Correct 34 ms 8424 KB Output is correct
15 Correct 38 ms 8276 KB Output is correct
16 Correct 35 ms 8332 KB Output is correct
17 Correct 32 ms 8276 KB Output is correct
18 Correct 361 ms 74404 KB Output is correct
19 Correct 372 ms 74372 KB Output is correct
20 Correct 399 ms 74396 KB Output is correct
21 Correct 31 ms 8380 KB Output is correct
22 Correct 31 ms 8368 KB Output is correct
23 Correct 72 ms 4576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 32 ms 6628 KB Output is correct
3 Correct 32 ms 6692 KB Output is correct
4 Correct 409 ms 62956 KB Output is correct
5 Correct 36 ms 6680 KB Output is correct
6 Correct 39 ms 6484 KB Output is correct
7 Correct 33 ms 6596 KB Output is correct
8 Correct 45 ms 6484 KB Output is correct
9 Correct 39 ms 6672 KB Output is correct
10 Correct 33 ms 6476 KB Output is correct
11 Correct 34 ms 6488 KB Output is correct
12 Correct 33 ms 6640 KB Output is correct
13 Correct 36 ms 6480 KB Output is correct
14 Correct 395 ms 62804 KB Output is correct
15 Correct 30 ms 6532 KB Output is correct
16 Correct 359 ms 74424 KB Output is correct
17 Correct 432 ms 74532 KB Output is correct
18 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 3 ms 1056 KB Output is correct
3 Correct 3 ms 936 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 384 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 0 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 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 34 ms 6688 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 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 126 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 340 ms 62880 KB Output is correct
31 Correct 375 ms 63060 KB Output is correct
32 Correct 402 ms 74656 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 365 ms 74800 KB Output is correct
35 Correct 378 ms 74340 KB Output is correct
36 Correct 380 ms 74436 KB Output is correct
37 Correct 377 ms 74488 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 29 ms 8284 KB Output is correct
40 Correct 29 ms 8332 KB Output is correct
41 Correct 35 ms 8292 KB Output is correct
42 Correct 33 ms 8272 KB Output is correct
43 Correct 31 ms 8332 KB Output is correct
44 Correct 33 ms 8532 KB Output is correct
45 Correct 30 ms 8376 KB Output is correct
46 Correct 34 ms 8388 KB Output is correct
47 Correct 34 ms 8424 KB Output is correct
48 Correct 38 ms 8276 KB Output is correct
49 Correct 35 ms 8332 KB Output is correct
50 Correct 32 ms 8276 KB Output is correct
51 Correct 361 ms 74404 KB Output is correct
52 Correct 372 ms 74372 KB Output is correct
53 Correct 399 ms 74396 KB Output is correct
54 Correct 31 ms 8380 KB Output is correct
55 Correct 31 ms 8368 KB Output is correct
56 Correct 72 ms 4576 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 32 ms 6628 KB Output is correct
59 Correct 32 ms 6692 KB Output is correct
60 Correct 409 ms 62956 KB Output is correct
61 Correct 36 ms 6680 KB Output is correct
62 Correct 39 ms 6484 KB Output is correct
63 Correct 33 ms 6596 KB Output is correct
64 Correct 45 ms 6484 KB Output is correct
65 Correct 39 ms 6672 KB Output is correct
66 Correct 33 ms 6476 KB Output is correct
67 Correct 34 ms 6488 KB Output is correct
68 Correct 33 ms 6640 KB Output is correct
69 Correct 36 ms 6480 KB Output is correct
70 Correct 395 ms 62804 KB Output is correct
71 Correct 30 ms 6532 KB Output is correct
72 Correct 359 ms 74424 KB Output is correct
73 Correct 432 ms 74532 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 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 4 ms 1112 KB Output is correct
80 Correct 417 ms 62816 KB Output is correct
81 Correct 363 ms 62868 KB Output is correct
82 Correct 377 ms 63056 KB Output is correct
83 Correct 428 ms 62888 KB Output is correct
84 Correct 444 ms 63008 KB Output is correct
85 Correct 385 ms 63056 KB Output is correct
86 Correct 82 ms 428 KB Output is correct
87 Correct 1 ms 344 KB Output is correct