Submission #203829

# Submission time Handle Problem Language Result Execution time Memory
203829 2020-02-22T11:53:36 Z georgerapeanu Strange Device (APIO19_strange_device) C++11
100 / 100
864 ms 69352 KB
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
long long a,b;

vector<pair<long long,int> > events;

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);

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

    vector<pair<long long,long long> > segm;

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

        if((r - l + 1) / a >= b){
            printf("%lld\n",a * b);
            return 0;
        }

        long long fst = (((l / b) % a) * (b) + (l % b));
        long long snd = (((r / b) % a) * (b) + (r % b));

        if(fst > snd){
            events.push_back({fst,1});
            events.push_back({(a - 1) * (b) + (b - 1) + 1,-1});
            events.push_back({0,1});
            events.push_back({snd + 1,-1});
        }
        else{
            events.push_back({fst,1});
            events.push_back({snd + 1,-1});
        }
    }

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

    long long ans = 0;
    long long lst = -1;
    int cnt_active = 0;

    for(auto it:events){
        ans += ((long long)(cnt_active > 0)) * (it.first - lst);
        lst = it.first;
        cnt_active += it.second;
    }

    printf("%lld\n",ans);

    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:21: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:29: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 4 ms 248 KB Output is correct
2 Correct 12 ms 1008 KB Output is correct
3 Correct 11 ms 884 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 11 ms 884 KB Output is correct
17 Correct 80 ms 4572 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 535 ms 33340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 685 ms 33344 KB Output is correct
3 Correct 706 ms 33212 KB Output is correct
4 Correct 707 ms 69152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 685 ms 33344 KB Output is correct
3 Correct 706 ms 33212 KB Output is correct
4 Correct 707 ms 69152 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 750 ms 69188 KB Output is correct
7 Correct 730 ms 69036 KB Output is correct
8 Correct 725 ms 69132 KB Output is correct
9 Correct 841 ms 68960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 685 ms 33344 KB Output is correct
3 Correct 706 ms 33212 KB Output is correct
4 Correct 707 ms 69152 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 79 ms 7388 KB Output is correct
7 Correct 76 ms 7368 KB Output is correct
8 Correct 73 ms 7540 KB Output is correct
9 Correct 70 ms 7268 KB Output is correct
10 Correct 73 ms 7268 KB Output is correct
11 Correct 76 ms 7276 KB Output is correct
12 Correct 72 ms 7268 KB Output is correct
13 Correct 77 ms 7268 KB Output is correct
14 Correct 74 ms 7388 KB Output is correct
15 Correct 83 ms 7268 KB Output is correct
16 Correct 82 ms 7432 KB Output is correct
17 Correct 73 ms 7240 KB Output is correct
18 Correct 765 ms 68876 KB Output is correct
19 Correct 707 ms 69204 KB Output is correct
20 Correct 854 ms 69008 KB Output is correct
21 Correct 91 ms 7388 KB Output is correct
22 Correct 65 ms 7268 KB Output is correct
23 Correct 235 ms 26708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 81 ms 6248 KB Output is correct
3 Correct 77 ms 6372 KB Output is correct
4 Correct 855 ms 69220 KB Output is correct
5 Correct 92 ms 7364 KB Output is correct
6 Correct 77 ms 7268 KB Output is correct
7 Correct 77 ms 7388 KB Output is correct
8 Correct 80 ms 7268 KB Output is correct
9 Correct 78 ms 7268 KB Output is correct
10 Correct 82 ms 7268 KB Output is correct
11 Correct 83 ms 7264 KB Output is correct
12 Correct 69 ms 7272 KB Output is correct
13 Correct 85 ms 7316 KB Output is correct
14 Correct 836 ms 69136 KB Output is correct
15 Correct 83 ms 7268 KB Output is correct
16 Correct 689 ms 69168 KB Output is correct
17 Correct 729 ms 69052 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 12 ms 1008 KB Output is correct
3 Correct 11 ms 884 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 11 ms 884 KB Output is correct
17 Correct 80 ms 4572 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 535 ms 33340 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 685 ms 33344 KB Output is correct
31 Correct 706 ms 33212 KB Output is correct
32 Correct 707 ms 69152 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 750 ms 69188 KB Output is correct
35 Correct 730 ms 69036 KB Output is correct
36 Correct 725 ms 69132 KB Output is correct
37 Correct 841 ms 68960 KB Output is correct
38 Correct 5 ms 256 KB Output is correct
39 Correct 79 ms 7388 KB Output is correct
40 Correct 76 ms 7368 KB Output is correct
41 Correct 73 ms 7540 KB Output is correct
42 Correct 70 ms 7268 KB Output is correct
43 Correct 73 ms 7268 KB Output is correct
44 Correct 76 ms 7276 KB Output is correct
45 Correct 72 ms 7268 KB Output is correct
46 Correct 77 ms 7268 KB Output is correct
47 Correct 74 ms 7388 KB Output is correct
48 Correct 83 ms 7268 KB Output is correct
49 Correct 82 ms 7432 KB Output is correct
50 Correct 73 ms 7240 KB Output is correct
51 Correct 765 ms 68876 KB Output is correct
52 Correct 707 ms 69204 KB Output is correct
53 Correct 854 ms 69008 KB Output is correct
54 Correct 91 ms 7388 KB Output is correct
55 Correct 65 ms 7268 KB Output is correct
56 Correct 235 ms 26708 KB Output is correct
57 Correct 5 ms 504 KB Output is correct
58 Correct 81 ms 6248 KB Output is correct
59 Correct 77 ms 6372 KB Output is correct
60 Correct 855 ms 69220 KB Output is correct
61 Correct 92 ms 7364 KB Output is correct
62 Correct 77 ms 7268 KB Output is correct
63 Correct 77 ms 7388 KB Output is correct
64 Correct 80 ms 7268 KB Output is correct
65 Correct 78 ms 7268 KB Output is correct
66 Correct 82 ms 7268 KB Output is correct
67 Correct 83 ms 7264 KB Output is correct
68 Correct 69 ms 7272 KB Output is correct
69 Correct 85 ms 7316 KB Output is correct
70 Correct 836 ms 69136 KB Output is correct
71 Correct 83 ms 7268 KB Output is correct
72 Correct 689 ms 69168 KB Output is correct
73 Correct 729 ms 69052 KB Output is correct
74 Correct 5 ms 256 KB Output is correct
75 Correct 4 ms 256 KB Output is correct
76 Correct 5 ms 256 KB Output is correct
77 Correct 5 ms 256 KB Output is correct
78 Correct 5 ms 256 KB Output is correct
79 Correct 12 ms 1396 KB Output is correct
80 Correct 864 ms 68832 KB Output is correct
81 Correct 847 ms 69000 KB Output is correct
82 Correct 830 ms 68908 KB Output is correct
83 Correct 806 ms 68944 KB Output is correct
84 Correct 789 ms 69352 KB Output is correct
85 Correct 814 ms 68964 KB Output is correct
86 Correct 234 ms 26704 KB Output is correct
87 Correct 5 ms 256 KB Output is correct