Submission #710531

# Submission time Handle Problem Language Result Execution time Memory
710531 2023-03-15T10:24:50 Z Ronin13 Strange Device (APIO19_strange_device) C++14
100 / 100
645 ms 53364 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 1000001;


int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    ll a, b; cin >> a >> b;
    ll l[n + 1], r[n + 1];
    for(int i = 1; i <= n; i++)
        cin >> l[i] >> r[i];
    ll o = 2e18;
    if(o / a < b + 1){
        ll s = 0;
        for(int i = 1; i <= n; i++)
            s += (r[i] - l[i] + 1);
        cout << s << "\n";
        return 0;
    }
    ll x = __gcd(a, b + 1);
    x = a / x * b;
    vector <pll> vec;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(l[i] / x == r[i] / x){
            vec.pb({l[i] % x, 1});
            vec.pb({r[i] % x + 1, -1});
        }
        else{
            vec.pb({l[i] % x, 1});
            vec.pb({x, -1});
            vec.pb({0, 1});
            vec.pb({r[i] % x + 1, -1});
        }
    }
    sort(vec.begin(), vec.end());
    ll ans = 0;
    ll last = -1;
    for(auto to : vec){
        ll x = to.f, y = to.s;
        if(cnt == 0){
            last = x;
        }
        cnt += y;
        if(cnt == 0){
            ans += x - last;
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1496 KB Output is correct
3 Correct 5 ms 1496 KB Output is correct
4 Correct 1 ms 316 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1480 KB Output is correct
17 Correct 57 ms 9772 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 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 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 320 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 371 ms 51056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 517 ms 53216 KB Output is correct
3 Correct 549 ms 53320 KB Output is correct
4 Correct 484 ms 53280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 517 ms 53216 KB Output is correct
3 Correct 549 ms 53320 KB Output is correct
4 Correct 484 ms 53280 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 519 ms 53248 KB Output is correct
7 Correct 496 ms 53364 KB Output is correct
8 Correct 486 ms 53352 KB Output is correct
9 Correct 594 ms 53236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 517 ms 53216 KB Output is correct
3 Correct 549 ms 53320 KB Output is correct
4 Correct 484 ms 53280 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 54 ms 9788 KB Output is correct
7 Correct 53 ms 9772 KB Output is correct
8 Correct 51 ms 9772 KB Output is correct
9 Correct 51 ms 9796 KB Output is correct
10 Correct 48 ms 9800 KB Output is correct
11 Correct 50 ms 9792 KB Output is correct
12 Correct 49 ms 9776 KB Output is correct
13 Correct 56 ms 9776 KB Output is correct
14 Correct 53 ms 9776 KB Output is correct
15 Correct 77 ms 9800 KB Output is correct
16 Correct 56 ms 9768 KB Output is correct
17 Correct 50 ms 9788 KB Output is correct
18 Correct 538 ms 53308 KB Output is correct
19 Correct 490 ms 53244 KB Output is correct
20 Correct 597 ms 53176 KB Output is correct
21 Correct 57 ms 9776 KB Output is correct
22 Correct 44 ms 9772 KB Output is correct
23 Correct 142 ms 34800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 57 ms 9772 KB Output is correct
3 Correct 55 ms 9776 KB Output is correct
4 Correct 615 ms 53184 KB Output is correct
5 Correct 56 ms 9776 KB Output is correct
6 Correct 51 ms 9788 KB Output is correct
7 Correct 53 ms 9796 KB Output is correct
8 Correct 56 ms 9796 KB Output is correct
9 Correct 53 ms 9780 KB Output is correct
10 Correct 56 ms 9772 KB Output is correct
11 Correct 58 ms 9772 KB Output is correct
12 Correct 49 ms 9780 KB Output is correct
13 Correct 57 ms 9776 KB Output is correct
14 Correct 554 ms 53016 KB Output is correct
15 Correct 61 ms 9788 KB Output is correct
16 Correct 509 ms 53020 KB Output is correct
17 Correct 487 ms 53040 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1496 KB Output is correct
3 Correct 5 ms 1496 KB Output is correct
4 Correct 1 ms 316 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1480 KB Output is correct
17 Correct 57 ms 9772 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 371 ms 51056 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 517 ms 53216 KB Output is correct
31 Correct 549 ms 53320 KB Output is correct
32 Correct 484 ms 53280 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 519 ms 53248 KB Output is correct
35 Correct 496 ms 53364 KB Output is correct
36 Correct 486 ms 53352 KB Output is correct
37 Correct 594 ms 53236 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 54 ms 9788 KB Output is correct
40 Correct 53 ms 9772 KB Output is correct
41 Correct 51 ms 9772 KB Output is correct
42 Correct 51 ms 9796 KB Output is correct
43 Correct 48 ms 9800 KB Output is correct
44 Correct 50 ms 9792 KB Output is correct
45 Correct 49 ms 9776 KB Output is correct
46 Correct 56 ms 9776 KB Output is correct
47 Correct 53 ms 9776 KB Output is correct
48 Correct 77 ms 9800 KB Output is correct
49 Correct 56 ms 9768 KB Output is correct
50 Correct 50 ms 9788 KB Output is correct
51 Correct 538 ms 53308 KB Output is correct
52 Correct 490 ms 53244 KB Output is correct
53 Correct 597 ms 53176 KB Output is correct
54 Correct 57 ms 9776 KB Output is correct
55 Correct 44 ms 9772 KB Output is correct
56 Correct 142 ms 34800 KB Output is correct
57 Correct 1 ms 272 KB Output is correct
58 Correct 57 ms 9772 KB Output is correct
59 Correct 55 ms 9776 KB Output is correct
60 Correct 615 ms 53184 KB Output is correct
61 Correct 56 ms 9776 KB Output is correct
62 Correct 51 ms 9788 KB Output is correct
63 Correct 53 ms 9796 KB Output is correct
64 Correct 56 ms 9796 KB Output is correct
65 Correct 53 ms 9780 KB Output is correct
66 Correct 56 ms 9772 KB Output is correct
67 Correct 58 ms 9772 KB Output is correct
68 Correct 49 ms 9780 KB Output is correct
69 Correct 57 ms 9776 KB Output is correct
70 Correct 554 ms 53016 KB Output is correct
71 Correct 61 ms 9788 KB Output is correct
72 Correct 509 ms 53020 KB Output is correct
73 Correct 487 ms 53040 KB Output is correct
74 Correct 1 ms 324 KB Output is correct
75 Correct 1 ms 316 KB Output is correct
76 Correct 0 ms 324 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 320 KB Output is correct
79 Correct 7 ms 1492 KB Output is correct
80 Correct 625 ms 52900 KB Output is correct
81 Correct 645 ms 52784 KB Output is correct
82 Correct 566 ms 52748 KB Output is correct
83 Correct 604 ms 52468 KB Output is correct
84 Correct 585 ms 51932 KB Output is correct
85 Correct 572 ms 51204 KB Output is correct
86 Correct 148 ms 34632 KB Output is correct
87 Correct 1 ms 212 KB Output is correct