Submission #562760

# Submission time Handle Problem Language Result Execution time Memory
562760 2022-05-15T08:32:16 Z tatyam Strange Device (APIO19_strange_device) C++17
100 / 100
820 ms 113428 KB
#include <iostream>
#include <vector>
#include <numeric>
#include <map>
using namespace std;
using u64 = uint64_t;
const u64 MAX = 1e18;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    u64 A, B;
    cin >> n >> A >> B;
    A /= gcd(A, B + 1);
    const u64 P = MAX / A < B ? MAX + 1 : A * B;
    vector<pair<u64, u64>> range(n);
    map<u64, int> imos;
    for(auto& [L, R] : range){
        cin >> L >> R;
        R++;
        if(R - L >= P){
            cout << P << endl;
            return 0;
        }
        L %= P;
        R %= P;
        imos[L]++;
        imos[R]--;
        if(L > R){
            imos[0]++;
            imos[P]--;
        }
    }
    u64 ans = 0, prev = 0, cnt = 0;
    for(auto [key, val] : imos){
        if(cnt) ans += key - prev;
        cnt += val;
        prev = key;
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1492 KB Output is correct
3 Correct 6 ms 1400 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 7 ms 1440 KB Output is correct
17 Correct 80 ms 11756 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 400 KB Output is correct
5 Correct 264 ms 18260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 693 ms 87656 KB Output is correct
3 Correct 699 ms 88948 KB Output is correct
4 Correct 742 ms 108592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 693 ms 87656 KB Output is correct
3 Correct 699 ms 88948 KB Output is correct
4 Correct 742 ms 108592 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 718 ms 108804 KB Output is correct
7 Correct 739 ms 106932 KB Output is correct
8 Correct 707 ms 107132 KB Output is correct
9 Correct 820 ms 100936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 693 ms 87656 KB Output is correct
3 Correct 699 ms 88948 KB Output is correct
4 Correct 742 ms 108592 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 55 ms 11848 KB Output is correct
7 Correct 59 ms 11852 KB Output is correct
8 Correct 72 ms 11852 KB Output is correct
9 Correct 65 ms 11796 KB Output is correct
10 Correct 58 ms 11816 KB Output is correct
11 Correct 57 ms 11848 KB Output is correct
12 Correct 58 ms 11780 KB Output is correct
13 Correct 83 ms 11808 KB Output is correct
14 Correct 60 ms 11904 KB Output is correct
15 Correct 75 ms 11820 KB Output is correct
16 Correct 68 ms 11852 KB Output is correct
17 Correct 72 ms 11776 KB Output is correct
18 Correct 687 ms 98988 KB Output is correct
19 Correct 739 ms 107640 KB Output is correct
20 Correct 777 ms 109920 KB Output is correct
21 Correct 62 ms 11812 KB Output is correct
22 Correct 59 ms 11824 KB Output is correct
23 Correct 113 ms 14568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 67 ms 11852 KB Output is correct
3 Correct 72 ms 11852 KB Output is correct
4 Correct 733 ms 89324 KB Output is correct
5 Correct 70 ms 11832 KB Output is correct
6 Correct 73 ms 11848 KB Output is correct
7 Correct 78 ms 11776 KB Output is correct
8 Correct 65 ms 11800 KB Output is correct
9 Correct 64 ms 11872 KB Output is correct
10 Correct 68 ms 11824 KB Output is correct
11 Correct 64 ms 11760 KB Output is correct
12 Correct 64 ms 11804 KB Output is correct
13 Correct 66 ms 11780 KB Output is correct
14 Correct 772 ms 113428 KB Output is correct
15 Correct 59 ms 11864 KB Output is correct
16 Correct 719 ms 99248 KB Output is correct
17 Correct 650 ms 112912 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1492 KB Output is correct
3 Correct 6 ms 1400 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 7 ms 1440 KB Output is correct
17 Correct 80 ms 11756 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 400 KB Output is correct
28 Correct 264 ms 18260 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 693 ms 87656 KB Output is correct
31 Correct 699 ms 88948 KB Output is correct
32 Correct 742 ms 108592 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 718 ms 108804 KB Output is correct
35 Correct 739 ms 106932 KB Output is correct
36 Correct 707 ms 107132 KB Output is correct
37 Correct 820 ms 100936 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 55 ms 11848 KB Output is correct
40 Correct 59 ms 11852 KB Output is correct
41 Correct 72 ms 11852 KB Output is correct
42 Correct 65 ms 11796 KB Output is correct
43 Correct 58 ms 11816 KB Output is correct
44 Correct 57 ms 11848 KB Output is correct
45 Correct 58 ms 11780 KB Output is correct
46 Correct 83 ms 11808 KB Output is correct
47 Correct 60 ms 11904 KB Output is correct
48 Correct 75 ms 11820 KB Output is correct
49 Correct 68 ms 11852 KB Output is correct
50 Correct 72 ms 11776 KB Output is correct
51 Correct 687 ms 98988 KB Output is correct
52 Correct 739 ms 107640 KB Output is correct
53 Correct 777 ms 109920 KB Output is correct
54 Correct 62 ms 11812 KB Output is correct
55 Correct 59 ms 11824 KB Output is correct
56 Correct 113 ms 14568 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 67 ms 11852 KB Output is correct
59 Correct 72 ms 11852 KB Output is correct
60 Correct 733 ms 89324 KB Output is correct
61 Correct 70 ms 11832 KB Output is correct
62 Correct 73 ms 11848 KB Output is correct
63 Correct 78 ms 11776 KB Output is correct
64 Correct 65 ms 11800 KB Output is correct
65 Correct 64 ms 11872 KB Output is correct
66 Correct 68 ms 11824 KB Output is correct
67 Correct 64 ms 11760 KB Output is correct
68 Correct 64 ms 11804 KB Output is correct
69 Correct 66 ms 11780 KB Output is correct
70 Correct 772 ms 113428 KB Output is correct
71 Correct 59 ms 11864 KB Output is correct
72 Correct 719 ms 99248 KB Output is correct
73 Correct 650 ms 112912 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 8 ms 1484 KB Output is correct
80 Correct 763 ms 99320 KB Output is correct
81 Correct 783 ms 99048 KB Output is correct
82 Correct 764 ms 98860 KB Output is correct
83 Correct 776 ms 98376 KB Output is correct
84 Correct 806 ms 98428 KB Output is correct
85 Correct 793 ms 98188 KB Output is correct
86 Correct 115 ms 15088 KB Output is correct
87 Correct 1 ms 320 KB Output is correct