Submission #210207

# Submission time Handle Problem Language Result Execution time Memory
210207 2020-03-16T20:05:22 Z tatyam Strange Device (APIO19_strange_device) C++17
100 / 100
775 ms 33756 KB
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
#define rep(n) for(int i=0;i<n;++i)
#define all(i) begin(i),end(i)
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))



using u128 = __uint128_t;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ull n, a, b;
    cin >> n >> a >> b;
    u128 mod = a / gcd(a, b + 1) * u128(b);
    vector<pair<ull, int>> query;
    rep(n){
        ull l, r;
        cin >> l >> r;
        if(r - l + 1 >= mod){
            cout << ull(mod) << endl;
            return 0;
        }
        l %= mod; r %= mod;
        r++;
        query.emplace_back(l, 1);
        query.emplace_back(r, -1);
        if(l > r){
            query.emplace_back(mod, -1);
            query.emplace_back(0, 1);
        }
    }
    Sort(query);
    Rev(query);
    ull at = 0, cnt = 0, ans = 0;
    while(query.size()){
        ull next = query.back().first;
        if(cnt) ans += next - at;
        at = next;
        while(query.size() && query.back().first == at){
            cnt += query.back().second;
            query.pop_back();
        }
    }
    cout << ans << endl;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:4:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(n) for(int i=0;i<n;++i)
                            ~^~~~~~~~
 #define all(i) begin(i),end(i)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #define Sort(a) sort(all(a))
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #define Rev(a) reverse(all(a))
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 ~                            
 
 ~                            
 
 ~                            
 using u128 = __uint128_t;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~   
 signed main(){
 ~~~~~~~~~~~~~~~              
     cin.tie(nullptr);
     ~~~~~~~~~~~~~~~~~~       
     ios::sync_with_stdio(false);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     ull n, a, b;
     ~~~~~~~~~~~~~            
     cin >> n >> a >> b;
     ~~~~~~~~~~~~~~~~~~~~     
     u128 mod = a / gcd(a, b + 1) * u128(b);
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     vector<pair<ull, int>> query;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     rep(n){
     ~~~~~                    
strange_device.cpp:19:5: note: in expansion of macro 'rep'
     rep(n){
     ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 14 ms 1160 KB Output is correct
3 Correct 11 ms 1144 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 11 ms 1144 KB Output is correct
17 Correct 87 ms 4712 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 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 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 452 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 437 ms 33712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 673 ms 33708 KB Output is correct
3 Correct 731 ms 33752 KB Output is correct
4 Correct 602 ms 33728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 673 ms 33708 KB Output is correct
3 Correct 731 ms 33752 KB Output is correct
4 Correct 602 ms 33728 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 622 ms 33732 KB Output is correct
7 Correct 601 ms 33728 KB Output is correct
8 Correct 619 ms 33728 KB Output is correct
9 Correct 705 ms 33728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 673 ms 33708 KB Output is correct
3 Correct 731 ms 33752 KB Output is correct
4 Correct 602 ms 33728 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 67 ms 4968 KB Output is correct
7 Correct 68 ms 4968 KB Output is correct
8 Correct 62 ms 4964 KB Output is correct
9 Correct 64 ms 4964 KB Output is correct
10 Correct 61 ms 4964 KB Output is correct
11 Correct 65 ms 4968 KB Output is correct
12 Correct 64 ms 4968 KB Output is correct
13 Correct 70 ms 4968 KB Output is correct
14 Correct 62 ms 4972 KB Output is correct
15 Correct 73 ms 4968 KB Output is correct
16 Correct 70 ms 4968 KB Output is correct
17 Correct 68 ms 4968 KB Output is correct
18 Correct 635 ms 33756 KB Output is correct
19 Correct 596 ms 33728 KB Output is correct
20 Correct 756 ms 33728 KB Output is correct
21 Correct 73 ms 4972 KB Output is correct
22 Correct 58 ms 4968 KB Output is correct
23 Correct 179 ms 17232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 70 ms 4968 KB Output is correct
3 Correct 74 ms 4968 KB Output is correct
4 Correct 768 ms 33728 KB Output is correct
5 Correct 70 ms 4968 KB Output is correct
6 Correct 71 ms 4968 KB Output is correct
7 Correct 71 ms 4968 KB Output is correct
8 Correct 73 ms 4932 KB Output is correct
9 Correct 69 ms 4968 KB Output is correct
10 Correct 77 ms 4968 KB Output is correct
11 Correct 71 ms 4968 KB Output is correct
12 Correct 63 ms 4968 KB Output is correct
13 Correct 96 ms 4968 KB Output is correct
14 Correct 747 ms 33748 KB Output is correct
15 Correct 73 ms 4968 KB Output is correct
16 Correct 596 ms 33728 KB Output is correct
17 Correct 639 ms 33728 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 14 ms 1160 KB Output is correct
3 Correct 11 ms 1144 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 11 ms 1144 KB Output is correct
17 Correct 87 ms 4712 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 6 ms 452 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 437 ms 33712 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 673 ms 33708 KB Output is correct
31 Correct 731 ms 33752 KB Output is correct
32 Correct 602 ms 33728 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 622 ms 33732 KB Output is correct
35 Correct 601 ms 33728 KB Output is correct
36 Correct 619 ms 33728 KB Output is correct
37 Correct 705 ms 33728 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 67 ms 4968 KB Output is correct
40 Correct 68 ms 4968 KB Output is correct
41 Correct 62 ms 4964 KB Output is correct
42 Correct 64 ms 4964 KB Output is correct
43 Correct 61 ms 4964 KB Output is correct
44 Correct 65 ms 4968 KB Output is correct
45 Correct 64 ms 4968 KB Output is correct
46 Correct 70 ms 4968 KB Output is correct
47 Correct 62 ms 4972 KB Output is correct
48 Correct 73 ms 4968 KB Output is correct
49 Correct 70 ms 4968 KB Output is correct
50 Correct 68 ms 4968 KB Output is correct
51 Correct 635 ms 33756 KB Output is correct
52 Correct 596 ms 33728 KB Output is correct
53 Correct 756 ms 33728 KB Output is correct
54 Correct 73 ms 4972 KB Output is correct
55 Correct 58 ms 4968 KB Output is correct
56 Correct 179 ms 17232 KB Output is correct
57 Correct 5 ms 376 KB Output is correct
58 Correct 70 ms 4968 KB Output is correct
59 Correct 74 ms 4968 KB Output is correct
60 Correct 768 ms 33728 KB Output is correct
61 Correct 70 ms 4968 KB Output is correct
62 Correct 71 ms 4968 KB Output is correct
63 Correct 71 ms 4968 KB Output is correct
64 Correct 73 ms 4932 KB Output is correct
65 Correct 69 ms 4968 KB Output is correct
66 Correct 77 ms 4968 KB Output is correct
67 Correct 71 ms 4968 KB Output is correct
68 Correct 63 ms 4968 KB Output is correct
69 Correct 96 ms 4968 KB Output is correct
70 Correct 747 ms 33748 KB Output is correct
71 Correct 73 ms 4968 KB Output is correct
72 Correct 596 ms 33728 KB Output is correct
73 Correct 639 ms 33728 KB Output is correct
74 Correct 5 ms 376 KB Output is correct
75 Correct 5 ms 376 KB Output is correct
76 Correct 5 ms 376 KB Output is correct
77 Correct 4 ms 376 KB Output is correct
78 Correct 5 ms 376 KB Output is correct
79 Correct 10 ms 1272 KB Output is correct
80 Correct 756 ms 33608 KB Output is correct
81 Correct 775 ms 33604 KB Output is correct
82 Correct 731 ms 33600 KB Output is correct
83 Correct 711 ms 33596 KB Output is correct
84 Correct 723 ms 33600 KB Output is correct
85 Correct 746 ms 33600 KB Output is correct
86 Correct 177 ms 17108 KB Output is correct
87 Correct 5 ms 376 KB Output is correct