Submission #333530

# Submission time Handle Problem Language Result Execution time Memory
333530 2020-12-06T21:00:23 Z SorahISA Strange Device (APIO19_strange_device) C++17
100 / 100
835 ms 82980 KB
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fastIO() ios_base::sync_with_stdio(false), cin.tie(0)

void solve() {
    int n, A, B;
    cin >> n >> A >> B;
    
    int cyc = log10(A) - log10(__gcd(A, B+1)) + log10(B) > 18.01 ? (int)1E18 + 100 : A / __gcd(A, B+1) * B;
    map<int, int> pre;
    
    while (n--) {
        int L, R;
        cin >> L >> R;
        if (R - L + 1 >= cyc) ++pre[0], --pre[cyc];
        else {
            L %= cyc, R %= cyc;
            if (L > R) ++pre[L], --pre[cyc], ++pre[0], --pre[R+1];
            else ++pre[L], --pre[R+1];
        }
    }
    
    int ans = 0, sum = 0, lst = 0;
    for (auto [key, val] : pre) {
        if (sum) ans += key - lst;
        sum += val, lst = key;
    }
    cout << ans << "\n";
}

int32_t main() {
    fastIO();
    
    int t = 1; // cin >> t;
    while (t--) solve();
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1388 KB Output is correct
17 Correct 76 ms 10464 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 296 ms 25600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 768 ms 82540 KB Output is correct
3 Correct 750 ms 77900 KB Output is correct
4 Correct 791 ms 77932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 768 ms 82540 KB Output is correct
3 Correct 750 ms 77900 KB Output is correct
4 Correct 791 ms 77932 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 765 ms 77932 KB Output is correct
7 Correct 753 ms 78120 KB Output is correct
8 Correct 733 ms 78060 KB Output is correct
9 Correct 823 ms 77932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 768 ms 82540 KB Output is correct
3 Correct 750 ms 77900 KB Output is correct
4 Correct 791 ms 77932 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 65 ms 10348 KB Output is correct
7 Correct 74 ms 10476 KB Output is correct
8 Correct 69 ms 10348 KB Output is correct
9 Correct 73 ms 10348 KB Output is correct
10 Correct 70 ms 10348 KB Output is correct
11 Correct 68 ms 10476 KB Output is correct
12 Correct 70 ms 10348 KB Output is correct
13 Correct 72 ms 10496 KB Output is correct
14 Correct 68 ms 10348 KB Output is correct
15 Correct 77 ms 10348 KB Output is correct
16 Correct 74 ms 10348 KB Output is correct
17 Correct 71 ms 10348 KB Output is correct
18 Correct 751 ms 78104 KB Output is correct
19 Correct 775 ms 77124 KB Output is correct
20 Correct 830 ms 77556 KB Output is correct
21 Correct 69 ms 10348 KB Output is correct
22 Correct 80 ms 10476 KB Output is correct
23 Correct 128 ms 13008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 75 ms 10476 KB Output is correct
3 Correct 75 ms 10348 KB Output is correct
4 Correct 804 ms 82636 KB Output is correct
5 Correct 75 ms 10348 KB Output is correct
6 Correct 77 ms 10348 KB Output is correct
7 Correct 76 ms 10348 KB Output is correct
8 Correct 75 ms 10348 KB Output is correct
9 Correct 74 ms 10348 KB Output is correct
10 Correct 69 ms 10348 KB Output is correct
11 Correct 70 ms 10368 KB Output is correct
12 Correct 75 ms 10348 KB Output is correct
13 Correct 75 ms 10368 KB Output is correct
14 Correct 816 ms 78392 KB Output is correct
15 Correct 67 ms 10348 KB Output is correct
16 Correct 741 ms 78832 KB Output is correct
17 Correct 749 ms 78800 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1388 KB Output is correct
17 Correct 76 ms 10464 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 376 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 296 ms 25600 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 768 ms 82540 KB Output is correct
31 Correct 750 ms 77900 KB Output is correct
32 Correct 791 ms 77932 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 765 ms 77932 KB Output is correct
35 Correct 753 ms 78120 KB Output is correct
36 Correct 733 ms 78060 KB Output is correct
37 Correct 823 ms 77932 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 65 ms 10348 KB Output is correct
40 Correct 74 ms 10476 KB Output is correct
41 Correct 69 ms 10348 KB Output is correct
42 Correct 73 ms 10348 KB Output is correct
43 Correct 70 ms 10348 KB Output is correct
44 Correct 68 ms 10476 KB Output is correct
45 Correct 70 ms 10348 KB Output is correct
46 Correct 72 ms 10496 KB Output is correct
47 Correct 68 ms 10348 KB Output is correct
48 Correct 77 ms 10348 KB Output is correct
49 Correct 74 ms 10348 KB Output is correct
50 Correct 71 ms 10348 KB Output is correct
51 Correct 751 ms 78104 KB Output is correct
52 Correct 775 ms 77124 KB Output is correct
53 Correct 830 ms 77556 KB Output is correct
54 Correct 69 ms 10348 KB Output is correct
55 Correct 80 ms 10476 KB Output is correct
56 Correct 128 ms 13008 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 75 ms 10476 KB Output is correct
59 Correct 75 ms 10348 KB Output is correct
60 Correct 804 ms 82636 KB Output is correct
61 Correct 75 ms 10348 KB Output is correct
62 Correct 77 ms 10348 KB Output is correct
63 Correct 76 ms 10348 KB Output is correct
64 Correct 75 ms 10348 KB Output is correct
65 Correct 74 ms 10348 KB Output is correct
66 Correct 69 ms 10348 KB Output is correct
67 Correct 70 ms 10368 KB Output is correct
68 Correct 75 ms 10348 KB Output is correct
69 Correct 75 ms 10368 KB Output is correct
70 Correct 816 ms 78392 KB Output is correct
71 Correct 67 ms 10348 KB Output is correct
72 Correct 741 ms 78832 KB Output is correct
73 Correct 749 ms 78800 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 7 ms 1388 KB Output is correct
80 Correct 824 ms 79692 KB Output is correct
81 Correct 803 ms 77108 KB Output is correct
82 Correct 835 ms 76372 KB Output is correct
83 Correct 814 ms 81912 KB Output is correct
84 Correct 830 ms 82980 KB Output is correct
85 Correct 784 ms 80464 KB Output is correct
86 Correct 131 ms 12908 KB Output is correct
87 Correct 1 ms 364 KB Output is correct