Submission #128537

# Submission time Handle Problem Language Result Execution time Memory
128537 2019-07-11T06:07:14 Z ae04071 Strange Device (APIO19_strange_device) C++11
100 / 100
923 ms 34684 KB
#include <bits/stdc++.h>
using namespace std;
using lli = long long;

const lli INF = 2e18;
lli mul(lli a,lli b) {
    if(a>=INF || b>=INF || INF/a<b) return INF;
    else return min(INF, a*b);
}
int main() {
    int n;
    lli A,B;
    scanf("%d%lld%lld",&n,&A,&B);

    lli g = __gcd(A-1,B), s = abs(B-A+1) / g;
    lli kg = __gcd(s, A), k = A / kg;
    //lli I = mul(k, B/g);
    lli I = mul(mul(k, B/g), g);

    vector<pair<lli,int>> arr;
    for(int i=0;i<n;i++) {
        lli l,r;
        scanf("%lld%lld",&l,&r);
        if(r-l+1>=I) {
            arr.push_back({0,1});
            arr.push_back({I,-1});
        } else {
            l%=I; r%=I;
            if(l<=r) {
                arr.push_back({l,1});
                arr.push_back({r+1,-1});
            } else {
                arr.push_back({0,1});
                arr.push_back({r+1,-1});
                arr.push_back({l,1});
                arr.push_back({I,-1});
            }
        }
    }
    
    lli ans=0,ad=0,pr=0;
    sort(arr.begin(),arr.end());
    for(int i=0,j=0;i<(int)arr.size();i=j) {
        ans += (arr[i].first - pr) * min(ad, 1ll);
        for(j=i;j<(int)arr.size() && arr[i].first==arr[j].first;j++) {
            ad += arr[j].second;
        }
        pr = arr[i].first;
    }
    printf("%lld\n",ans);
    
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:13: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:23: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 256 KB Output is correct
2 Correct 9 ms 1396 KB Output is correct
3 Correct 9 ms 1396 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 296 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 9 ms 1268 KB Output is correct
17 Correct 80 ms 5732 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 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 424 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 408 KB Output is correct
5 Correct 518 ms 34572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 673 ms 34684 KB Output is correct
3 Correct 721 ms 33680 KB Output is correct
4 Correct 684 ms 33700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 673 ms 34684 KB Output is correct
3 Correct 721 ms 33680 KB Output is correct
4 Correct 684 ms 33700 KB Output is correct
5 Correct 2 ms 324 KB Output is correct
6 Correct 711 ms 33696 KB Output is correct
7 Correct 674 ms 33864 KB Output is correct
8 Correct 700 ms 33948 KB Output is correct
9 Correct 824 ms 34144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 673 ms 34684 KB Output is correct
3 Correct 721 ms 33680 KB Output is correct
4 Correct 684 ms 33700 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 69 ms 6116 KB Output is correct
7 Correct 74 ms 6192 KB Output is correct
8 Correct 68 ms 6244 KB Output is correct
9 Correct 96 ms 6248 KB Output is correct
10 Correct 67 ms 6400 KB Output is correct
11 Correct 73 ms 6504 KB Output is correct
12 Correct 68 ms 6508 KB Output is correct
13 Correct 79 ms 6500 KB Output is correct
14 Correct 69 ms 6500 KB Output is correct
15 Correct 80 ms 6628 KB Output is correct
16 Correct 78 ms 6756 KB Output is correct
17 Correct 73 ms 6708 KB Output is correct
18 Correct 719 ms 34156 KB Output is correct
19 Correct 662 ms 34116 KB Output is correct
20 Correct 834 ms 34108 KB Output is correct
21 Correct 82 ms 6500 KB Output is correct
22 Correct 63 ms 6416 KB Output is correct
23 Correct 228 ms 19340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 77 ms 6152 KB Output is correct
3 Correct 78 ms 6504 KB Output is correct
4 Correct 889 ms 34212 KB Output is correct
5 Correct 78 ms 6628 KB Output is correct
6 Correct 78 ms 6628 KB Output is correct
7 Correct 78 ms 6628 KB Output is correct
8 Correct 80 ms 6628 KB Output is correct
9 Correct 75 ms 6628 KB Output is correct
10 Correct 80 ms 6668 KB Output is correct
11 Correct 78 ms 6888 KB Output is correct
12 Correct 69 ms 6804 KB Output is correct
13 Correct 80 ms 6884 KB Output is correct
14 Correct 799 ms 34152 KB Output is correct
15 Correct 81 ms 6924 KB Output is correct
16 Correct 656 ms 34060 KB Output is correct
17 Correct 691 ms 34108 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1396 KB Output is correct
3 Correct 9 ms 1396 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 296 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 9 ms 1268 KB Output is correct
17 Correct 80 ms 5732 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 380 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 424 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 408 KB Output is correct
28 Correct 518 ms 34572 KB Output is correct
29 Correct 2 ms 252 KB Output is correct
30 Correct 673 ms 34684 KB Output is correct
31 Correct 721 ms 33680 KB Output is correct
32 Correct 684 ms 33700 KB Output is correct
33 Correct 2 ms 324 KB Output is correct
34 Correct 711 ms 33696 KB Output is correct
35 Correct 674 ms 33864 KB Output is correct
36 Correct 700 ms 33948 KB Output is correct
37 Correct 824 ms 34144 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 69 ms 6116 KB Output is correct
40 Correct 74 ms 6192 KB Output is correct
41 Correct 68 ms 6244 KB Output is correct
42 Correct 96 ms 6248 KB Output is correct
43 Correct 67 ms 6400 KB Output is correct
44 Correct 73 ms 6504 KB Output is correct
45 Correct 68 ms 6508 KB Output is correct
46 Correct 79 ms 6500 KB Output is correct
47 Correct 69 ms 6500 KB Output is correct
48 Correct 80 ms 6628 KB Output is correct
49 Correct 78 ms 6756 KB Output is correct
50 Correct 73 ms 6708 KB Output is correct
51 Correct 719 ms 34156 KB Output is correct
52 Correct 662 ms 34116 KB Output is correct
53 Correct 834 ms 34108 KB Output is correct
54 Correct 82 ms 6500 KB Output is correct
55 Correct 63 ms 6416 KB Output is correct
56 Correct 228 ms 19340 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 77 ms 6152 KB Output is correct
59 Correct 78 ms 6504 KB Output is correct
60 Correct 889 ms 34212 KB Output is correct
61 Correct 78 ms 6628 KB Output is correct
62 Correct 78 ms 6628 KB Output is correct
63 Correct 78 ms 6628 KB Output is correct
64 Correct 80 ms 6628 KB Output is correct
65 Correct 75 ms 6628 KB Output is correct
66 Correct 80 ms 6668 KB Output is correct
67 Correct 78 ms 6888 KB Output is correct
68 Correct 69 ms 6804 KB Output is correct
69 Correct 80 ms 6884 KB Output is correct
70 Correct 799 ms 34152 KB Output is correct
71 Correct 81 ms 6924 KB Output is correct
72 Correct 656 ms 34060 KB Output is correct
73 Correct 691 ms 34108 KB Output is correct
74 Correct 2 ms 256 KB Output is correct
75 Correct 2 ms 252 KB Output is correct
76 Correct 2 ms 252 KB Output is correct
77 Correct 2 ms 256 KB Output is correct
78 Correct 2 ms 256 KB Output is correct
79 Correct 9 ms 1268 KB Output is correct
80 Correct 923 ms 34164 KB Output is correct
81 Correct 880 ms 34188 KB Output is correct
82 Correct 791 ms 34172 KB Output is correct
83 Correct 792 ms 34236 KB Output is correct
84 Correct 798 ms 34144 KB Output is correct
85 Correct 823 ms 34208 KB Output is correct
86 Correct 230 ms 20472 KB Output is correct
87 Correct 2 ms 256 KB Output is correct