Submission #139532

# Submission time Handle Problem Language Result Execution time Memory
139532 2019-08-01T00:37:10 Z jovan_b Strange Device (APIO19_strange_device) C++17
100 / 100
980 ms 34808 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

vector <pair <ll, ll>> vec;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    a /= __gcd(a, b+1);
    if(a <= 2000000000000000000LL/b) a *= b;
    //cout << a << endl;
    while(n--){
        ll l, r;
        cin >> l >> r;
        if(r-l+1 >= a){
            cout << a << "\n";
            return 0;
        }
        l %= a;
        r %= a;
        if(l > r){
            vec.push_back({0, 1});
            vec.push_back({r+1, -1});
            vec.push_back({l, 1});
            vec.push_back({a, -1});
        }
        else{
            vec.push_back({l, 1});
            vec.push_back({r+1, -1});
        }
    }
    sort(vec.begin(), vec.end());
    n = vec.size();
    ll res = 0;
    ll tren = 0;
    for(int i=0; i<n; i++){
        ll val = vec[i].first;
        //cout << vec[i].first << " " << vec[i].second << endl;
        if(i > 0) val -= vec[i-1].first;
        if(tren) res += val;
        tren += vec[i].second;
        //cout << res << endl;
    }
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 1400 KB Output is correct
3 Correct 10 ms 1400 KB Output is correct
4 Correct 2 ms 376 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 348 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 252 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 10 ms 1268 KB Output is correct
17 Correct 92 ms 6024 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 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 268 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 376 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 8 ms 480 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 535 ms 34432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 763 ms 34616 KB Output is correct
3 Correct 808 ms 34304 KB Output is correct
4 Correct 769 ms 34212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 763 ms 34616 KB Output is correct
3 Correct 808 ms 34304 KB Output is correct
4 Correct 769 ms 34212 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 791 ms 34348 KB Output is correct
7 Correct 756 ms 34496 KB Output is correct
8 Correct 770 ms 34364 KB Output is correct
9 Correct 898 ms 34116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 763 ms 34616 KB Output is correct
3 Correct 808 ms 34304 KB Output is correct
4 Correct 769 ms 34212 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 76 ms 5352 KB Output is correct
7 Correct 80 ms 5352 KB Output is correct
8 Correct 77 ms 5476 KB Output is correct
9 Correct 79 ms 5292 KB Output is correct
10 Correct 73 ms 5268 KB Output is correct
11 Correct 78 ms 5608 KB Output is correct
12 Correct 75 ms 5668 KB Output is correct
13 Correct 86 ms 5704 KB Output is correct
14 Correct 76 ms 5540 KB Output is correct
15 Correct 91 ms 5544 KB Output is correct
16 Correct 88 ms 5480 KB Output is correct
17 Correct 78 ms 5460 KB Output is correct
18 Correct 790 ms 34468 KB Output is correct
19 Correct 750 ms 34528 KB Output is correct
20 Correct 901 ms 34664 KB Output is correct
21 Correct 89 ms 6140 KB Output is correct
22 Correct 70 ms 6116 KB Output is correct
23 Correct 224 ms 18768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 85 ms 5488 KB Output is correct
3 Correct 85 ms 5904 KB Output is correct
4 Correct 980 ms 34624 KB Output is correct
5 Correct 86 ms 6120 KB Output is correct
6 Correct 86 ms 6124 KB Output is correct
7 Correct 89 ms 6024 KB Output is correct
8 Correct 91 ms 6344 KB Output is correct
9 Correct 84 ms 6372 KB Output is correct
10 Correct 89 ms 6664 KB Output is correct
11 Correct 85 ms 6508 KB Output is correct
12 Correct 78 ms 6508 KB Output is correct
13 Correct 89 ms 6504 KB Output is correct
14 Correct 886 ms 34672 KB Output is correct
15 Correct 91 ms 6440 KB Output is correct
16 Correct 737 ms 34764 KB Output is correct
17 Correct 769 ms 34652 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 10 ms 1400 KB Output is correct
3 Correct 10 ms 1400 KB Output is correct
4 Correct 2 ms 376 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 348 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 252 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 10 ms 1268 KB Output is correct
17 Correct 92 ms 6024 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 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 268 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 18 ms 376 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 8 ms 480 KB Output is correct
27 Correct 3 ms 488 KB Output is correct
28 Correct 535 ms 34432 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 763 ms 34616 KB Output is correct
31 Correct 808 ms 34304 KB Output is correct
32 Correct 769 ms 34212 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 791 ms 34348 KB Output is correct
35 Correct 756 ms 34496 KB Output is correct
36 Correct 770 ms 34364 KB Output is correct
37 Correct 898 ms 34116 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 76 ms 5352 KB Output is correct
40 Correct 80 ms 5352 KB Output is correct
41 Correct 77 ms 5476 KB Output is correct
42 Correct 79 ms 5292 KB Output is correct
43 Correct 73 ms 5268 KB Output is correct
44 Correct 78 ms 5608 KB Output is correct
45 Correct 75 ms 5668 KB Output is correct
46 Correct 86 ms 5704 KB Output is correct
47 Correct 76 ms 5540 KB Output is correct
48 Correct 91 ms 5544 KB Output is correct
49 Correct 88 ms 5480 KB Output is correct
50 Correct 78 ms 5460 KB Output is correct
51 Correct 790 ms 34468 KB Output is correct
52 Correct 750 ms 34528 KB Output is correct
53 Correct 901 ms 34664 KB Output is correct
54 Correct 89 ms 6140 KB Output is correct
55 Correct 70 ms 6116 KB Output is correct
56 Correct 224 ms 18768 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 85 ms 5488 KB Output is correct
59 Correct 85 ms 5904 KB Output is correct
60 Correct 980 ms 34624 KB Output is correct
61 Correct 86 ms 6120 KB Output is correct
62 Correct 86 ms 6124 KB Output is correct
63 Correct 89 ms 6024 KB Output is correct
64 Correct 91 ms 6344 KB Output is correct
65 Correct 84 ms 6372 KB Output is correct
66 Correct 89 ms 6664 KB Output is correct
67 Correct 85 ms 6508 KB Output is correct
68 Correct 78 ms 6508 KB Output is correct
69 Correct 89 ms 6504 KB Output is correct
70 Correct 886 ms 34672 KB Output is correct
71 Correct 91 ms 6440 KB Output is correct
72 Correct 737 ms 34764 KB Output is correct
73 Correct 769 ms 34652 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 9 ms 1400 KB Output is correct
80 Correct 971 ms 34808 KB Output is correct
81 Correct 975 ms 34628 KB Output is correct
82 Correct 866 ms 34616 KB Output is correct
83 Correct 863 ms 34728 KB Output is correct
84 Correct 885 ms 34632 KB Output is correct
85 Correct 875 ms 34708 KB Output is correct
86 Correct 232 ms 18840 KB Output is correct
87 Correct 2 ms 376 KB Output is correct