Submission #197510

# Submission time Handle Problem Language Result Execution time Memory
197510 2020-01-21T13:22:10 Z handlename Strange Device (APIO19_strange_device) C++17
100 / 100
751 ms 53440 KB
#include <bits/stdc++.h>
using namespace std;
long long n,a,b,l,r,m,ans;
vector<pair<long long,long long> > arr;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>a>>b;
    a=a/(__gcd(a,b+1));
    if (b>1e18/a){
        while (n--){
            cin>>l>>r;
            ans+=r-l+1;
        }
        cout<<ans;
        return 0;
    }
    m=a*b;
    while (n--){
        cin>>l>>r;
        if (r-m>=l){
            cout<<m;
            return 0;
        }
        if (l/m==r/m) arr.push_back(make_pair(l%m,r%m));
        else {
            arr.push_back(make_pair(0,r%m));
            arr.push_back(make_pair(l%m,m-1));
        }
    }
    sort(arr.begin(),arr.end());
    long long s=arr[0].first,e=arr[0].second;
    for (int i=1;i<arr.size();i++){
        if (arr[i].first>e){
            ans+=e-s+1;
            s=arr[i].first;
            e=arr[i].second;
        }
        else {
            e=max(e,arr[i].second);
        }
    }
    ans+=e-s+1;
    cout<<ans;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=1;i<arr.size();i++){
                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 8 ms 1020 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 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 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 68 ms 5736 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 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 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 456 ms 41536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 616 ms 53300 KB Output is correct
3 Correct 613 ms 53240 KB Output is correct
4 Correct 615 ms 53248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 616 ms 53300 KB Output is correct
3 Correct 613 ms 53240 KB Output is correct
4 Correct 615 ms 53248 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 615 ms 53424 KB Output is correct
7 Correct 616 ms 53388 KB Output is correct
8 Correct 614 ms 52792 KB Output is correct
9 Correct 679 ms 53376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 616 ms 53300 KB Output is correct
3 Correct 613 ms 53240 KB Output is correct
4 Correct 615 ms 53248 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 62 ms 5728 KB Output is correct
7 Correct 66 ms 5864 KB Output is correct
8 Correct 60 ms 5736 KB Output is correct
9 Correct 64 ms 5736 KB Output is correct
10 Correct 61 ms 5736 KB Output is correct
11 Correct 64 ms 5740 KB Output is correct
12 Correct 61 ms 5708 KB Output is correct
13 Correct 67 ms 5880 KB Output is correct
14 Correct 60 ms 5736 KB Output is correct
15 Correct 68 ms 5740 KB Output is correct
16 Correct 66 ms 5736 KB Output is correct
17 Correct 64 ms 5844 KB Output is correct
18 Correct 618 ms 52796 KB Output is correct
19 Correct 608 ms 53244 KB Output is correct
20 Correct 672 ms 53368 KB Output is correct
21 Correct 67 ms 5740 KB Output is correct
22 Correct 60 ms 5844 KB Output is correct
23 Correct 195 ms 18556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 66 ms 5736 KB Output is correct
3 Correct 66 ms 5708 KB Output is correct
4 Correct 683 ms 53296 KB Output is correct
5 Correct 66 ms 5736 KB Output is correct
6 Correct 68 ms 5876 KB Output is correct
7 Correct 66 ms 5736 KB Output is correct
8 Correct 68 ms 5736 KB Output is correct
9 Correct 66 ms 5736 KB Output is correct
10 Correct 66 ms 5736 KB Output is correct
11 Correct 78 ms 5716 KB Output is correct
12 Correct 60 ms 5736 KB Output is correct
13 Correct 67 ms 5736 KB Output is correct
14 Correct 668 ms 53136 KB Output is correct
15 Correct 66 ms 5760 KB Output is correct
16 Correct 695 ms 53440 KB Output is correct
17 Correct 602 ms 53276 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 9 ms 1144 KB Output is correct
3 Correct 8 ms 1020 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 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 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 68 ms 5736 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 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 508 KB Output is correct
28 Correct 456 ms 41536 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 616 ms 53300 KB Output is correct
31 Correct 613 ms 53240 KB Output is correct
32 Correct 615 ms 53248 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 615 ms 53424 KB Output is correct
35 Correct 616 ms 53388 KB Output is correct
36 Correct 614 ms 52792 KB Output is correct
37 Correct 679 ms 53376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 62 ms 5728 KB Output is correct
40 Correct 66 ms 5864 KB Output is correct
41 Correct 60 ms 5736 KB Output is correct
42 Correct 64 ms 5736 KB Output is correct
43 Correct 61 ms 5736 KB Output is correct
44 Correct 64 ms 5740 KB Output is correct
45 Correct 61 ms 5708 KB Output is correct
46 Correct 67 ms 5880 KB Output is correct
47 Correct 60 ms 5736 KB Output is correct
48 Correct 68 ms 5740 KB Output is correct
49 Correct 66 ms 5736 KB Output is correct
50 Correct 64 ms 5844 KB Output is correct
51 Correct 618 ms 52796 KB Output is correct
52 Correct 608 ms 53244 KB Output is correct
53 Correct 672 ms 53368 KB Output is correct
54 Correct 67 ms 5740 KB Output is correct
55 Correct 60 ms 5844 KB Output is correct
56 Correct 195 ms 18556 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 66 ms 5736 KB Output is correct
59 Correct 66 ms 5708 KB Output is correct
60 Correct 683 ms 53296 KB Output is correct
61 Correct 66 ms 5736 KB Output is correct
62 Correct 68 ms 5876 KB Output is correct
63 Correct 66 ms 5736 KB Output is correct
64 Correct 68 ms 5736 KB Output is correct
65 Correct 66 ms 5736 KB Output is correct
66 Correct 66 ms 5736 KB Output is correct
67 Correct 78 ms 5716 KB Output is correct
68 Correct 60 ms 5736 KB Output is correct
69 Correct 67 ms 5736 KB Output is correct
70 Correct 668 ms 53136 KB Output is correct
71 Correct 66 ms 5760 KB Output is correct
72 Correct 695 ms 53440 KB Output is correct
73 Correct 602 ms 53276 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 8 ms 1144 KB Output is correct
80 Correct 751 ms 53140 KB Output is correct
81 Correct 691 ms 53116 KB Output is correct
82 Correct 662 ms 53440 KB Output is correct
83 Correct 662 ms 53360 KB Output is correct
84 Correct 666 ms 52592 KB Output is correct
85 Correct 663 ms 53204 KB Output is correct
86 Correct 193 ms 18660 KB Output is correct
87 Correct 2 ms 376 KB Output is correct