Submission #897821

# Submission time Handle Problem Language Result Execution time Memory
897821 2024-01-03T18:13:20 Z Dec0Dedd Strange Device (APIO19_strange_device) C++14
100 / 100
1377 ms 118904 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

void solve() {
    ll n, a, b; cin>>n>>a>>b;
    a/=__gcd(a, b+1);

    ll md=1e18+10;
    if (a <= LLONG_MAX/b) md=a*b;

    map<ll, ll> cnt;
    for (int i=1; i<=n; ++i) {
        ll lf, rf; cin>>lf>>rf;

        if (rf-lf+1 >= md) {
            cout<<md<<"\n";
            return;
        } lf%=md, rf%=md;

        if (lf <= rf) {
            ++cnt[lf], --cnt[rf+1];
        } else {
            ++cnt[lf], --cnt[md];
            ++cnt[0], --cnt[rf+1];
        }
    } vector<pii> v;
    for (auto u : cnt) v.push_back(u);

    ll ans=0, sz=v.size(), sm=0;
    for (int i=0; i+1<sz; ++i) {
        sm+=v[i].second;
        if (sm > 0) ans+=v[i+1].first-v[i].first;
    } cout<<ans<<"\n";
}

int main() {
    int t=1; //cin>>t;
    while (t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 14 ms 1756 KB Output is correct
3 Correct 12 ms 1760 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 344 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 11 ms 1628 KB Output is correct
17 Correct 119 ms 12492 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 604 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 658 ms 25620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1234 ms 118848 KB Output is correct
3 Correct 1207 ms 116908 KB Output is correct
4 Correct 1281 ms 117640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1234 ms 118848 KB Output is correct
3 Correct 1207 ms 116908 KB Output is correct
4 Correct 1281 ms 117640 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1207 ms 118476 KB Output is correct
7 Correct 1245 ms 118672 KB Output is correct
8 Correct 1251 ms 117168 KB Output is correct
9 Correct 1339 ms 117612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1234 ms 118848 KB Output is correct
3 Correct 1207 ms 116908 KB Output is correct
4 Correct 1281 ms 117640 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 111 ms 12492 KB Output is correct
7 Correct 111 ms 12496 KB Output is correct
8 Correct 113 ms 12488 KB Output is correct
9 Correct 116 ms 12488 KB Output is correct
10 Correct 114 ms 12492 KB Output is correct
11 Correct 111 ms 12496 KB Output is correct
12 Correct 114 ms 12488 KB Output is correct
13 Correct 118 ms 12496 KB Output is correct
14 Correct 111 ms 12492 KB Output is correct
15 Correct 119 ms 12416 KB Output is correct
16 Correct 118 ms 12488 KB Output is correct
17 Correct 120 ms 12480 KB Output is correct
18 Correct 1189 ms 118248 KB Output is correct
19 Correct 1283 ms 117944 KB Output is correct
20 Correct 1301 ms 116816 KB Output is correct
21 Correct 137 ms 12528 KB Output is correct
22 Correct 115 ms 12488 KB Output is correct
23 Correct 326 ms 13088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 122 ms 12444 KB Output is correct
3 Correct 119 ms 12556 KB Output is correct
4 Correct 1321 ms 117856 KB Output is correct
5 Correct 120 ms 12396 KB Output is correct
6 Correct 118 ms 12484 KB Output is correct
7 Correct 122 ms 12488 KB Output is correct
8 Correct 120 ms 12432 KB Output is correct
9 Correct 115 ms 12380 KB Output is correct
10 Correct 116 ms 12500 KB Output is correct
11 Correct 115 ms 12364 KB Output is correct
12 Correct 114 ms 12352 KB Output is correct
13 Correct 119 ms 12600 KB Output is correct
14 Correct 1377 ms 117792 KB Output is correct
15 Correct 119 ms 12756 KB Output is correct
16 Correct 1178 ms 118864 KB Output is correct
17 Correct 1177 ms 117388 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 14 ms 1756 KB Output is correct
3 Correct 12 ms 1760 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 344 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 11 ms 1628 KB Output is correct
17 Correct 119 ms 12492 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 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 604 KB Output is correct
26 Correct 2 ms 520 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 658 ms 25620 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1234 ms 118848 KB Output is correct
31 Correct 1207 ms 116908 KB Output is correct
32 Correct 1281 ms 117640 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1207 ms 118476 KB Output is correct
35 Correct 1245 ms 118672 KB Output is correct
36 Correct 1251 ms 117168 KB Output is correct
37 Correct 1339 ms 117612 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 111 ms 12492 KB Output is correct
40 Correct 111 ms 12496 KB Output is correct
41 Correct 113 ms 12488 KB Output is correct
42 Correct 116 ms 12488 KB Output is correct
43 Correct 114 ms 12492 KB Output is correct
44 Correct 111 ms 12496 KB Output is correct
45 Correct 114 ms 12488 KB Output is correct
46 Correct 118 ms 12496 KB Output is correct
47 Correct 111 ms 12492 KB Output is correct
48 Correct 119 ms 12416 KB Output is correct
49 Correct 118 ms 12488 KB Output is correct
50 Correct 120 ms 12480 KB Output is correct
51 Correct 1189 ms 118248 KB Output is correct
52 Correct 1283 ms 117944 KB Output is correct
53 Correct 1301 ms 116816 KB Output is correct
54 Correct 137 ms 12528 KB Output is correct
55 Correct 115 ms 12488 KB Output is correct
56 Correct 326 ms 13088 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 122 ms 12444 KB Output is correct
59 Correct 119 ms 12556 KB Output is correct
60 Correct 1321 ms 117856 KB Output is correct
61 Correct 120 ms 12396 KB Output is correct
62 Correct 118 ms 12484 KB Output is correct
63 Correct 122 ms 12488 KB Output is correct
64 Correct 120 ms 12432 KB Output is correct
65 Correct 115 ms 12380 KB Output is correct
66 Correct 116 ms 12500 KB Output is correct
67 Correct 115 ms 12364 KB Output is correct
68 Correct 114 ms 12352 KB Output is correct
69 Correct 119 ms 12600 KB Output is correct
70 Correct 1377 ms 117792 KB Output is correct
71 Correct 119 ms 12756 KB Output is correct
72 Correct 1178 ms 118864 KB Output is correct
73 Correct 1177 ms 117388 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 436 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 12 ms 1828 KB Output is correct
80 Correct 1237 ms 117024 KB Output is correct
81 Correct 1235 ms 116912 KB Output is correct
82 Correct 1262 ms 117132 KB Output is correct
83 Correct 1289 ms 118480 KB Output is correct
84 Correct 1344 ms 118904 KB Output is correct
85 Correct 1273 ms 118024 KB Output is correct
86 Correct 306 ms 12944 KB Output is correct
87 Correct 1 ms 344 KB Output is correct