Submission #211477

# Submission time Handle Problem Language Result Execution time Memory
211477 2020-03-20T13:11:13 Z VEGAnn Strange Device (APIO19_strange_device) C++14
100 / 100
709 ms 33600 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pll pair<ll, ll>
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
//typedef long long __int128;
vector<pll> seg;
int n;
ll A, B;

int main(){

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#else
    ios_base::sync_with_stdio(0); cin.tie(0);
#endif // _LOCAL

    cin >> n >> A >> B;

    ll fi = A;
    ll gc = __gcd(A, B + 1);

    if (A / gc > ll(2e18) / B)
        fi = ll(2e18);
    else fi = A / gc * B;

    seg.clear();

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

        if (r - l + 1 >= fi){
            seg.PB(MP(0, fi - 1));
            continue;
        }

        ll vl = ((l - 1) / fi) * fi + fi;

        if (vl > r){
            vl -= fi;
            seg.PB(MP(l - vl, r - vl));
        } else {
            vl -= fi;
            seg.PB(MP(l - vl, fi - 1));
            vl += fi;
            seg.PB(MP(0ll, r - vl));
        }
    }

    sort(all(seg));

    ll lst = -1, ans = 0;

    for (pll cr : seg)
        if (cr.ft > lst){
            ans += cr.sd - cr.ft + 1ll;
            lst = cr.sd;
        } else {

            ans += max(lst, cr.sd) - lst;
            lst = max(lst, cr.sd);
        }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 10 ms 1152 KB Output is correct
3 Correct 10 ms 1152 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 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 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 10 ms 1152 KB Output is correct
17 Correct 59 ms 3816 KB Output is correct
18 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 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 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 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 421 ms 33600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 513 ms 17596 KB Output is correct
3 Correct 484 ms 17620 KB Output is correct
4 Correct 709 ms 17504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 513 ms 17596 KB Output is correct
3 Correct 484 ms 17620 KB Output is correct
4 Correct 709 ms 17504 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 504 ms 17496 KB Output is correct
7 Correct 492 ms 17364 KB Output is correct
8 Correct 502 ms 17384 KB Output is correct
9 Correct 542 ms 17244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 513 ms 17596 KB Output is correct
3 Correct 484 ms 17620 KB Output is correct
4 Correct 709 ms 17504 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 54 ms 3832 KB Output is correct
7 Correct 57 ms 3832 KB Output is correct
8 Correct 55 ms 3824 KB Output is correct
9 Correct 56 ms 3824 KB Output is correct
10 Correct 63 ms 3756 KB Output is correct
11 Correct 54 ms 3824 KB Output is correct
12 Correct 52 ms 3824 KB Output is correct
13 Correct 59 ms 3824 KB Output is correct
14 Correct 52 ms 3832 KB Output is correct
15 Correct 60 ms 3824 KB Output is correct
16 Correct 57 ms 3824 KB Output is correct
17 Correct 55 ms 3828 KB Output is correct
18 Correct 503 ms 17492 KB Output is correct
19 Correct 489 ms 17364 KB Output is correct
20 Correct 551 ms 17564 KB Output is correct
21 Correct 58 ms 3824 KB Output is correct
22 Correct 50 ms 3824 KB Output is correct
23 Correct 182 ms 18936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 59 ms 3960 KB Output is correct
3 Correct 61 ms 3952 KB Output is correct
4 Correct 579 ms 17104 KB Output is correct
5 Correct 57 ms 3704 KB Output is correct
6 Correct 78 ms 3696 KB Output is correct
7 Correct 57 ms 3696 KB Output is correct
8 Correct 57 ms 3704 KB Output is correct
9 Correct 57 ms 3696 KB Output is correct
10 Correct 57 ms 3704 KB Output is correct
11 Correct 57 ms 3696 KB Output is correct
12 Correct 50 ms 3696 KB Output is correct
13 Correct 56 ms 3696 KB Output is correct
14 Correct 542 ms 17468 KB Output is correct
15 Correct 58 ms 3696 KB Output is correct
16 Correct 496 ms 17112 KB Output is correct
17 Correct 490 ms 17112 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 10 ms 1152 KB Output is correct
3 Correct 10 ms 1152 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 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 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 10 ms 1152 KB Output is correct
17 Correct 59 ms 3816 KB Output is correct
18 Correct 4 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 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 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 421 ms 33600 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 513 ms 17596 KB Output is correct
31 Correct 484 ms 17620 KB Output is correct
32 Correct 709 ms 17504 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 504 ms 17496 KB Output is correct
35 Correct 492 ms 17364 KB Output is correct
36 Correct 502 ms 17384 KB Output is correct
37 Correct 542 ms 17244 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 54 ms 3832 KB Output is correct
40 Correct 57 ms 3832 KB Output is correct
41 Correct 55 ms 3824 KB Output is correct
42 Correct 56 ms 3824 KB Output is correct
43 Correct 63 ms 3756 KB Output is correct
44 Correct 54 ms 3824 KB Output is correct
45 Correct 52 ms 3824 KB Output is correct
46 Correct 59 ms 3824 KB Output is correct
47 Correct 52 ms 3832 KB Output is correct
48 Correct 60 ms 3824 KB Output is correct
49 Correct 57 ms 3824 KB Output is correct
50 Correct 55 ms 3828 KB Output is correct
51 Correct 503 ms 17492 KB Output is correct
52 Correct 489 ms 17364 KB Output is correct
53 Correct 551 ms 17564 KB Output is correct
54 Correct 58 ms 3824 KB Output is correct
55 Correct 50 ms 3824 KB Output is correct
56 Correct 182 ms 18936 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 59 ms 3960 KB Output is correct
59 Correct 61 ms 3952 KB Output is correct
60 Correct 579 ms 17104 KB Output is correct
61 Correct 57 ms 3704 KB Output is correct
62 Correct 78 ms 3696 KB Output is correct
63 Correct 57 ms 3696 KB Output is correct
64 Correct 57 ms 3704 KB Output is correct
65 Correct 57 ms 3696 KB Output is correct
66 Correct 57 ms 3704 KB Output is correct
67 Correct 57 ms 3696 KB Output is correct
68 Correct 50 ms 3696 KB Output is correct
69 Correct 56 ms 3696 KB Output is correct
70 Correct 542 ms 17468 KB Output is correct
71 Correct 58 ms 3696 KB Output is correct
72 Correct 496 ms 17112 KB Output is correct
73 Correct 490 ms 17112 KB Output is correct
74 Correct 4 ms 384 KB Output is correct
75 Correct 4 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 4 ms 384 KB Output is correct
78 Correct 4 ms 384 KB Output is correct
79 Correct 10 ms 1152 KB Output is correct
80 Correct 585 ms 17400 KB Output is correct
81 Correct 561 ms 17108 KB Output is correct
82 Correct 533 ms 17108 KB Output is correct
83 Correct 543 ms 17296 KB Output is correct
84 Correct 571 ms 17112 KB Output is correct
85 Correct 548 ms 17108 KB Output is correct
86 Correct 188 ms 18732 KB Output is correct
87 Correct 5 ms 384 KB Output is correct