Submission #240507

# Submission time Handle Problem Language Result Execution time Memory
240507 2020-06-19T17:48:42 Z valerikk Strange Device (APIO19_strange_device) C++14
100 / 100
827 ms 46528 KB
#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

#define ll long long
#define ld long double
#define int long long

const int oo = 2e18 + 7;

bool ok(int a, int b) {
    return a <= oo / b;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    int p = a / __gcd(a, b + 1);
    if (ok(p, b)) p *= b; else p = oo;
    vector<pair<int, int>> v;
    while (n--) {
        int l, r;
        cin >> l >> r;
        int L = l % p, R = r % p;
        if (r - l + 1 >= p) {
            L = 0;
            R = p - 1;
        }
        l = L;
        r = R;
        if (l <= r) {
            v.pb({l, 1});
            v.pb({r + 1, -1});
        } else {
            v.pb({0, 1});
            v.pb({r + 1, -1});
            v.pb({l, 1});
            v.pb({p, -1});
        }
    }
    sort(all(v));
    int ans = 0, bal = 0;
    for (int i = 0; i + 1 < sz(v); i++) {
        bal += v[i].y;
        if (bal) ans += v[i + 1].x - v[i].x;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 11 ms 1024 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1024 KB Output is correct
17 Correct 77 ms 4588 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 416 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 440 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 655 ms 33344 KB Output is correct
3 Correct 667 ms 33352 KB Output is correct
4 Correct 628 ms 33340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 655 ms 33344 KB Output is correct
3 Correct 667 ms 33352 KB Output is correct
4 Correct 628 ms 33340 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 679 ms 33284 KB Output is correct
7 Correct 663 ms 33348 KB Output is correct
8 Correct 649 ms 33352 KB Output is correct
9 Correct 737 ms 33472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 655 ms 33344 KB Output is correct
3 Correct 667 ms 33352 KB Output is correct
4 Correct 628 ms 33340 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 70 ms 4588 KB Output is correct
7 Correct 68 ms 4588 KB Output is correct
8 Correct 71 ms 4588 KB Output is correct
9 Correct 67 ms 4596 KB Output is correct
10 Correct 63 ms 4584 KB Output is correct
11 Correct 67 ms 4588 KB Output is correct
12 Correct 64 ms 4584 KB Output is correct
13 Correct 69 ms 4588 KB Output is correct
14 Correct 64 ms 4588 KB Output is correct
15 Correct 75 ms 4460 KB Output is correct
16 Correct 71 ms 4596 KB Output is correct
17 Correct 68 ms 4596 KB Output is correct
18 Correct 663 ms 33492 KB Output is correct
19 Correct 628 ms 34368 KB Output is correct
20 Correct 755 ms 34368 KB Output is correct
21 Correct 76 ms 5612 KB Output is correct
22 Correct 62 ms 5640 KB Output is correct
23 Correct 184 ms 18004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 74 ms 4584 KB Output is correct
3 Correct 73 ms 4588 KB Output is correct
4 Correct 806 ms 33344 KB Output is correct
5 Correct 76 ms 4588 KB Output is correct
6 Correct 72 ms 4592 KB Output is correct
7 Correct 72 ms 4680 KB Output is correct
8 Correct 78 ms 4584 KB Output is correct
9 Correct 70 ms 4584 KB Output is correct
10 Correct 75 ms 4588 KB Output is correct
11 Correct 73 ms 4588 KB Output is correct
12 Correct 67 ms 4588 KB Output is correct
13 Correct 75 ms 4596 KB Output is correct
14 Correct 758 ms 33344 KB Output is correct
15 Correct 76 ms 4588 KB Output is correct
16 Correct 600 ms 33344 KB Output is correct
17 Correct 639 ms 33320 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 11 ms 1024 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1024 KB Output is correct
17 Correct 77 ms 4588 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 416 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 440 ms 33344 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 655 ms 33344 KB Output is correct
31 Correct 667 ms 33352 KB Output is correct
32 Correct 628 ms 33340 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 679 ms 33284 KB Output is correct
35 Correct 663 ms 33348 KB Output is correct
36 Correct 649 ms 33352 KB Output is correct
37 Correct 737 ms 33472 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 70 ms 4588 KB Output is correct
40 Correct 68 ms 4588 KB Output is correct
41 Correct 71 ms 4588 KB Output is correct
42 Correct 67 ms 4596 KB Output is correct
43 Correct 63 ms 4584 KB Output is correct
44 Correct 67 ms 4588 KB Output is correct
45 Correct 64 ms 4584 KB Output is correct
46 Correct 69 ms 4588 KB Output is correct
47 Correct 64 ms 4588 KB Output is correct
48 Correct 75 ms 4460 KB Output is correct
49 Correct 71 ms 4596 KB Output is correct
50 Correct 68 ms 4596 KB Output is correct
51 Correct 663 ms 33492 KB Output is correct
52 Correct 628 ms 34368 KB Output is correct
53 Correct 755 ms 34368 KB Output is correct
54 Correct 76 ms 5612 KB Output is correct
55 Correct 62 ms 5640 KB Output is correct
56 Correct 184 ms 18004 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 74 ms 4584 KB Output is correct
59 Correct 73 ms 4588 KB Output is correct
60 Correct 806 ms 33344 KB Output is correct
61 Correct 76 ms 4588 KB Output is correct
62 Correct 72 ms 4592 KB Output is correct
63 Correct 72 ms 4680 KB Output is correct
64 Correct 78 ms 4584 KB Output is correct
65 Correct 70 ms 4584 KB Output is correct
66 Correct 75 ms 4588 KB Output is correct
67 Correct 73 ms 4588 KB Output is correct
68 Correct 67 ms 4588 KB Output is correct
69 Correct 75 ms 4596 KB Output is correct
70 Correct 758 ms 33344 KB Output is correct
71 Correct 76 ms 4588 KB Output is correct
72 Correct 600 ms 33344 KB Output is correct
73 Correct 639 ms 33320 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 10 ms 1408 KB Output is correct
80 Correct 818 ms 40136 KB Output is correct
81 Correct 827 ms 40128 KB Output is correct
82 Correct 719 ms 40136 KB Output is correct
83 Correct 739 ms 41632 KB Output is correct
84 Correct 791 ms 46528 KB Output is correct
85 Correct 727 ms 39872 KB Output is correct
86 Correct 192 ms 26872 KB Output is correct
87 Correct 5 ms 384 KB Output is correct