Submission #153897

# Submission time Handle Problem Language Result Execution time Memory
153897 2019-09-17T11:14:47 Z DystoriaX Strange Device (APIO19_strange_device) C++14
100 / 100
650 ms 19940 KB
#include <bits/stdc++.h>

using namespace std;

int n;
long long a, b, mx;
const long long inf = 2e18;
vector<pair<long long, long long> > seg;

long long gcd(long long a, long long b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    scanf("%d%lld%lld", &n, &a, &b);

    mx = a / gcd(a, b + 1);

    if(inf / mx < b){
        mx = 1e18;
    } else mx *= b;

    for(int i = 0; i < n; i++){
        long long l, r;
        scanf("%lld%lld", &l, &r);

        if(r - l + 1 >= mx){
            seg.emplace_back(0, mx - 1);
            continue;
        }

        l %= mx, r %= mx;
        
        if (l <= r){
            seg.emplace_back(l, r);
        } else {
            seg.emplace_back(l, mx - 1);
            seg.emplace_back(0, r);
        }
    }

    sort(seg.begin(), seg.end());

    long long ans = 0, last = 0;

    for(auto k : seg){
        ans += max(0LL, k.second - max(last, k.first) + 1);
        last = max(last, k.second + 1);
    }

    printf("%lld\n", ans);
    
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%lld%lld", &n, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 8 ms 1016 KB Output is correct
17 Correct 64 ms 4972 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 439 ms 19212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 568 ms 19940 KB Output is correct
3 Correct 548 ms 19072 KB Output is correct
4 Correct 529 ms 18768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 568 ms 19940 KB Output is correct
3 Correct 548 ms 19072 KB Output is correct
4 Correct 529 ms 18768 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 538 ms 18784 KB Output is correct
7 Correct 570 ms 18896 KB Output is correct
8 Correct 551 ms 18640 KB Output is correct
9 Correct 592 ms 18768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 568 ms 19940 KB Output is correct
3 Correct 548 ms 19072 KB Output is correct
4 Correct 529 ms 18768 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 56 ms 4336 KB Output is correct
7 Correct 65 ms 4332 KB Output is correct
8 Correct 63 ms 4076 KB Output is correct
9 Correct 58 ms 4084 KB Output is correct
10 Correct 56 ms 4076 KB Output is correct
11 Correct 61 ms 4076 KB Output is correct
12 Correct 55 ms 4024 KB Output is correct
13 Correct 59 ms 4072 KB Output is correct
14 Correct 55 ms 4048 KB Output is correct
15 Correct 62 ms 4072 KB Output is correct
16 Correct 61 ms 4328 KB Output is correct
17 Correct 57 ms 4328 KB Output is correct
18 Correct 566 ms 18616 KB Output is correct
19 Correct 525 ms 18384 KB Output is correct
20 Correct 595 ms 18196 KB Output is correct
21 Correct 61 ms 3948 KB Output is correct
22 Correct 54 ms 3820 KB Output is correct
23 Correct 213 ms 11648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 61 ms 3608 KB Output is correct
3 Correct 62 ms 3672 KB Output is correct
4 Correct 642 ms 18000 KB Output is correct
5 Correct 59 ms 3944 KB Output is correct
6 Correct 60 ms 3948 KB Output is correct
7 Correct 58 ms 3560 KB Output is correct
8 Correct 61 ms 3816 KB Output is correct
9 Correct 60 ms 3948 KB Output is correct
10 Correct 60 ms 3820 KB Output is correct
11 Correct 63 ms 3860 KB Output is correct
12 Correct 52 ms 3812 KB Output is correct
13 Correct 62 ms 3684 KB Output is correct
14 Correct 599 ms 17504 KB Output is correct
15 Correct 59 ms 3048 KB Output is correct
16 Correct 551 ms 17388 KB Output is correct
17 Correct 560 ms 17868 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 8 ms 1016 KB Output is correct
17 Correct 64 ms 4972 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 252 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 439 ms 19212 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 568 ms 19940 KB Output is correct
31 Correct 548 ms 19072 KB Output is correct
32 Correct 529 ms 18768 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 538 ms 18784 KB Output is correct
35 Correct 570 ms 18896 KB Output is correct
36 Correct 551 ms 18640 KB Output is correct
37 Correct 592 ms 18768 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 56 ms 4336 KB Output is correct
40 Correct 65 ms 4332 KB Output is correct
41 Correct 63 ms 4076 KB Output is correct
42 Correct 58 ms 4084 KB Output is correct
43 Correct 56 ms 4076 KB Output is correct
44 Correct 61 ms 4076 KB Output is correct
45 Correct 55 ms 4024 KB Output is correct
46 Correct 59 ms 4072 KB Output is correct
47 Correct 55 ms 4048 KB Output is correct
48 Correct 62 ms 4072 KB Output is correct
49 Correct 61 ms 4328 KB Output is correct
50 Correct 57 ms 4328 KB Output is correct
51 Correct 566 ms 18616 KB Output is correct
52 Correct 525 ms 18384 KB Output is correct
53 Correct 595 ms 18196 KB Output is correct
54 Correct 61 ms 3948 KB Output is correct
55 Correct 54 ms 3820 KB Output is correct
56 Correct 213 ms 11648 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 61 ms 3608 KB Output is correct
59 Correct 62 ms 3672 KB Output is correct
60 Correct 642 ms 18000 KB Output is correct
61 Correct 59 ms 3944 KB Output is correct
62 Correct 60 ms 3948 KB Output is correct
63 Correct 58 ms 3560 KB Output is correct
64 Correct 61 ms 3816 KB Output is correct
65 Correct 60 ms 3948 KB Output is correct
66 Correct 60 ms 3820 KB Output is correct
67 Correct 63 ms 3860 KB Output is correct
68 Correct 52 ms 3812 KB Output is correct
69 Correct 62 ms 3684 KB Output is correct
70 Correct 599 ms 17504 KB Output is correct
71 Correct 59 ms 3048 KB Output is correct
72 Correct 551 ms 17388 KB Output is correct
73 Correct 560 ms 17868 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 3 ms 392 KB Output is correct
76 Correct 2 ms 256 KB Output is correct
77 Correct 3 ms 376 KB Output is correct
78 Correct 2 ms 256 KB Output is correct
79 Correct 8 ms 1016 KB Output is correct
80 Correct 610 ms 19908 KB Output is correct
81 Correct 609 ms 19664 KB Output is correct
82 Correct 586 ms 19792 KB Output is correct
83 Correct 571 ms 19724 KB Output is correct
84 Correct 571 ms 19920 KB Output is correct
85 Correct 650 ms 19892 KB Output is correct
86 Correct 214 ms 18652 KB Output is correct
87 Correct 2 ms 376 KB Output is correct