Submission #983137

# Submission time Handle Problem Language Result Execution time Memory
983137 2024-05-15T08:39:40 Z LittleOrange Strange Device (APIO19_strange_device) C++17
100 / 100
396 ms 80620 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll big = 1e18;
ll cal(ll a, ll b){
    __int128 g = gcd(a,b+1);
    __int128 x=a,y=b+1,w=b,z,lim = 2e18;
    z = x/g*w;
    if (z>lim) return lim;
    else return z;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    ll n,a,b;
    cin >> n >> a >> b;
    ll m = cal(a,b);
    //cout << m << "\n";
    vector<pair<ll,ll>> v;
    while(n--){
        ll l,r;
        cin >> l >> r;
        ll ml = (l+m-1)/m*m;
        ll mr = r/m*m;
        //cout << l << " " << r << " " << ml << " " << mr << "\n";
        if (ml<mr){
            v.push_back({0,m-1});
        }else if (ml>mr){
            v.push_back({l%m,r%m});
        }else{
            if(l%m)v.push_back({l%m,m-1});
            v.push_back({0,r%m});
        }
    }
    sort(v.begin(),v.end());
    //cout << "v:\n";for(auto &o : v) cout << o.first << " " << o.second << "\n";
    vector<pair<ll,ll>> u;
    for(auto &o : v){
        if (u.empty())u.push_back(o);
        else{
            if (u.back().second>=o.first) u.back().second = max(u.back().second,o.second);
            else{
                u.push_back(o);
            }
        }
    }
    //cout << "u:\n";for(auto &o : u) cout << o.first << " " << o.second << "\n";
    ll ans = 0;
    for(auto &o : u) ans += o.second-o.first+1;
    cout << ans << "\n";
}

Compilation message

strange_device.cpp: In function 'll cal(ll, ll)':
strange_device.cpp:8:18: warning: unused variable 'y' [-Wunused-variable]
    8 |     __int128 x=a,y=b+1,w=b,z,lim = 2e18;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 1244 KB Output is correct
3 Correct 4 ms 1248 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1232 KB Output is correct
17 Correct 38 ms 8680 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 240 ms 41356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 333 ms 78284 KB Output is correct
3 Correct 315 ms 78000 KB Output is correct
4 Correct 314 ms 78832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 333 ms 78284 KB Output is correct
3 Correct 315 ms 78000 KB Output is correct
4 Correct 314 ms 78832 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 322 ms 79472 KB Output is correct
7 Correct 339 ms 79284 KB Output is correct
8 Correct 329 ms 78692 KB Output is correct
9 Correct 342 ms 79972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 333 ms 78284 KB Output is correct
3 Correct 315 ms 78000 KB Output is correct
4 Correct 314 ms 78832 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 33 ms 8588 KB Output is correct
7 Correct 35 ms 8660 KB Output is correct
8 Correct 31 ms 8676 KB Output is correct
9 Correct 32 ms 8652 KB Output is correct
10 Correct 32 ms 8648 KB Output is correct
11 Correct 33 ms 8728 KB Output is correct
12 Correct 31 ms 8652 KB Output is correct
13 Correct 37 ms 8652 KB Output is correct
14 Correct 32 ms 8648 KB Output is correct
15 Correct 45 ms 8752 KB Output is correct
16 Correct 38 ms 8676 KB Output is correct
17 Correct 37 ms 8712 KB Output is correct
18 Correct 330 ms 79504 KB Output is correct
19 Correct 318 ms 78760 KB Output is correct
20 Correct 382 ms 78564 KB Output is correct
21 Correct 38 ms 8648 KB Output is correct
22 Correct 31 ms 8616 KB Output is correct
23 Correct 117 ms 20168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 36 ms 8684 KB Output is correct
3 Correct 39 ms 8676 KB Output is correct
4 Correct 396 ms 78512 KB Output is correct
5 Correct 34 ms 8652 KB Output is correct
6 Correct 50 ms 8848 KB Output is correct
7 Correct 34 ms 8736 KB Output is correct
8 Correct 38 ms 8668 KB Output is correct
9 Correct 38 ms 8784 KB Output is correct
10 Correct 40 ms 8676 KB Output is correct
11 Correct 38 ms 8652 KB Output is correct
12 Correct 29 ms 8732 KB Output is correct
13 Correct 35 ms 8576 KB Output is correct
14 Correct 368 ms 79028 KB Output is correct
15 Correct 35 ms 8648 KB Output is correct
16 Correct 352 ms 78088 KB Output is correct
17 Correct 342 ms 79764 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 1244 KB Output is correct
3 Correct 4 ms 1248 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1232 KB Output is correct
17 Correct 38 ms 8680 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 240 ms 41356 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 333 ms 78284 KB Output is correct
31 Correct 315 ms 78000 KB Output is correct
32 Correct 314 ms 78832 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 322 ms 79472 KB Output is correct
35 Correct 339 ms 79284 KB Output is correct
36 Correct 329 ms 78692 KB Output is correct
37 Correct 342 ms 79972 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 33 ms 8588 KB Output is correct
40 Correct 35 ms 8660 KB Output is correct
41 Correct 31 ms 8676 KB Output is correct
42 Correct 32 ms 8652 KB Output is correct
43 Correct 32 ms 8648 KB Output is correct
44 Correct 33 ms 8728 KB Output is correct
45 Correct 31 ms 8652 KB Output is correct
46 Correct 37 ms 8652 KB Output is correct
47 Correct 32 ms 8648 KB Output is correct
48 Correct 45 ms 8752 KB Output is correct
49 Correct 38 ms 8676 KB Output is correct
50 Correct 37 ms 8712 KB Output is correct
51 Correct 330 ms 79504 KB Output is correct
52 Correct 318 ms 78760 KB Output is correct
53 Correct 382 ms 78564 KB Output is correct
54 Correct 38 ms 8648 KB Output is correct
55 Correct 31 ms 8616 KB Output is correct
56 Correct 117 ms 20168 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 36 ms 8684 KB Output is correct
59 Correct 39 ms 8676 KB Output is correct
60 Correct 396 ms 78512 KB Output is correct
61 Correct 34 ms 8652 KB Output is correct
62 Correct 50 ms 8848 KB Output is correct
63 Correct 34 ms 8736 KB Output is correct
64 Correct 38 ms 8668 KB Output is correct
65 Correct 38 ms 8784 KB Output is correct
66 Correct 40 ms 8676 KB Output is correct
67 Correct 38 ms 8652 KB Output is correct
68 Correct 29 ms 8732 KB Output is correct
69 Correct 35 ms 8576 KB Output is correct
70 Correct 368 ms 79028 KB Output is correct
71 Correct 35 ms 8648 KB Output is correct
72 Correct 352 ms 78088 KB Output is correct
73 Correct 342 ms 79764 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 4 ms 1248 KB Output is correct
80 Correct 387 ms 77928 KB Output is correct
81 Correct 387 ms 78744 KB Output is correct
82 Correct 367 ms 78536 KB Output is correct
83 Correct 356 ms 79480 KB Output is correct
84 Correct 361 ms 80620 KB Output is correct
85 Correct 345 ms 78032 KB Output is correct
86 Correct 97 ms 20416 KB Output is correct
87 Correct 1 ms 344 KB Output is correct