Submission #741871

# Submission time Handle Problem Language Result Execution time Memory
741871 2023-05-15T03:07:41 Z becaido Strange Device (APIO19_strange_device) C++17
100 / 100
474 ms 53404 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const ll INF = 2e18;

int n;
ll a, b, len, ans;
vector<pair<ll, ll>> v;

void solve() {
    cin >> n >> a >> b;
    len = a / gcd(a, b + 1);
    if ((__int128) len * b >= INF) len = INF;
    else len *= b;
    while (n--) {
        ll l, r;
        cin >> l >> r;
        if (r - l + 1 >= len) {
            cout << len << '\n';
            return;
        }
        if (l % len <= r % len) v.pb(l % len, r % len);
        else v.pb(l % len, len - 1), v.pb(0, r % len);
    }
    sort(v.begin(), v.end());
    ll R = -1;
    for (auto [l, r] : v) {
        if (l > R) R = l;
        if (r >= R) {
            ans += r - R + 1;
            R = r + 1;
        }
    }
    cout << ans << '\n';
}

int main() {
    Waimai;
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 692 KB Output is correct
3 Correct 5 ms 600 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 684 KB Output is correct
17 Correct 42 ms 2488 KB Output is correct
18 Correct 0 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 310 ms 16776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 379 ms 16768 KB Output is correct
3 Correct 430 ms 16848 KB Output is correct
4 Correct 423 ms 53264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 379 ms 16768 KB Output is correct
3 Correct 430 ms 16848 KB Output is correct
4 Correct 423 ms 53264 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 404 ms 53400 KB Output is correct
7 Correct 400 ms 53204 KB Output is correct
8 Correct 422 ms 53236 KB Output is correct
9 Correct 436 ms 53300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 379 ms 16768 KB Output is correct
3 Correct 430 ms 16848 KB Output is correct
4 Correct 423 ms 53264 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 39 ms 5696 KB Output is correct
7 Correct 43 ms 5708 KB Output is correct
8 Correct 41 ms 5708 KB Output is correct
9 Correct 40 ms 5696 KB Output is correct
10 Correct 42 ms 5652 KB Output is correct
11 Correct 53 ms 5832 KB Output is correct
12 Correct 39 ms 5664 KB Output is correct
13 Correct 40 ms 5728 KB Output is correct
14 Correct 37 ms 5704 KB Output is correct
15 Correct 43 ms 5680 KB Output is correct
16 Correct 43 ms 5632 KB Output is correct
17 Correct 42 ms 5736 KB Output is correct
18 Correct 415 ms 53204 KB Output is correct
19 Correct 393 ms 53292 KB Output is correct
20 Correct 431 ms 53212 KB Output is correct
21 Correct 43 ms 5624 KB Output is correct
22 Correct 38 ms 5700 KB Output is correct
23 Correct 120 ms 18480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 40 ms 2512 KB Output is correct
3 Correct 39 ms 2512 KB Output is correct
4 Correct 474 ms 35812 KB Output is correct
5 Correct 40 ms 5692 KB Output is correct
6 Correct 43 ms 5828 KB Output is correct
7 Correct 43 ms 5672 KB Output is correct
8 Correct 42 ms 5608 KB Output is correct
9 Correct 41 ms 5700 KB Output is correct
10 Correct 40 ms 5608 KB Output is correct
11 Correct 40 ms 5692 KB Output is correct
12 Correct 35 ms 5620 KB Output is correct
13 Correct 57 ms 5624 KB Output is correct
14 Correct 442 ms 35748 KB Output is correct
15 Correct 44 ms 5708 KB Output is correct
16 Correct 401 ms 53240 KB Output is correct
17 Correct 405 ms 53272 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 692 KB Output is correct
3 Correct 5 ms 600 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 684 KB Output is correct
17 Correct 42 ms 2488 KB Output is correct
18 Correct 0 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 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 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 310 ms 16776 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 379 ms 16768 KB Output is correct
31 Correct 430 ms 16848 KB Output is correct
32 Correct 423 ms 53264 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 404 ms 53400 KB Output is correct
35 Correct 400 ms 53204 KB Output is correct
36 Correct 422 ms 53236 KB Output is correct
37 Correct 436 ms 53300 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 39 ms 5696 KB Output is correct
40 Correct 43 ms 5708 KB Output is correct
41 Correct 41 ms 5708 KB Output is correct
42 Correct 40 ms 5696 KB Output is correct
43 Correct 42 ms 5652 KB Output is correct
44 Correct 53 ms 5832 KB Output is correct
45 Correct 39 ms 5664 KB Output is correct
46 Correct 40 ms 5728 KB Output is correct
47 Correct 37 ms 5704 KB Output is correct
48 Correct 43 ms 5680 KB Output is correct
49 Correct 43 ms 5632 KB Output is correct
50 Correct 42 ms 5736 KB Output is correct
51 Correct 415 ms 53204 KB Output is correct
52 Correct 393 ms 53292 KB Output is correct
53 Correct 431 ms 53212 KB Output is correct
54 Correct 43 ms 5624 KB Output is correct
55 Correct 38 ms 5700 KB Output is correct
56 Correct 120 ms 18480 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 40 ms 2512 KB Output is correct
59 Correct 39 ms 2512 KB Output is correct
60 Correct 474 ms 35812 KB Output is correct
61 Correct 40 ms 5692 KB Output is correct
62 Correct 43 ms 5828 KB Output is correct
63 Correct 43 ms 5672 KB Output is correct
64 Correct 42 ms 5608 KB Output is correct
65 Correct 41 ms 5700 KB Output is correct
66 Correct 40 ms 5608 KB Output is correct
67 Correct 40 ms 5692 KB Output is correct
68 Correct 35 ms 5620 KB Output is correct
69 Correct 57 ms 5624 KB Output is correct
70 Correct 442 ms 35748 KB Output is correct
71 Correct 44 ms 5708 KB Output is correct
72 Correct 401 ms 53240 KB Output is correct
73 Correct 405 ms 53272 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 4 ms 976 KB Output is correct
80 Correct 445 ms 53220 KB Output is correct
81 Correct 453 ms 53380 KB Output is correct
82 Correct 420 ms 53208 KB Output is correct
83 Correct 436 ms 53292 KB Output is correct
84 Correct 439 ms 53404 KB Output is correct
85 Correct 441 ms 53272 KB Output is correct
86 Correct 121 ms 18480 KB Output is correct
87 Correct 0 ms 212 KB Output is correct