Submission #554333

# Submission time Handle Problem Language Result Execution time Memory
554333 2022-04-28T07:13:56 Z maomao90 Strange Device (APIO19_strange_device) C++17
100 / 100
682 ms 68300 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 1000005

int n;
ll a, b;
ll l[MAXN], r[MAXN];
ll ans;

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0); cin.tie(0);
#endif
    cin >> n >> a >> b;
    REP (i, 0, n) {
        cin >> l[i] >> r[i];
    }
    ll g = __gcd(b + 1, a);
    __int128 mx = (__int128) a / g * b;
    REP (i, 0, n) {
        if (r[i] - l[i] + 1 > mx) {
            cout << (ll) mx << '\n';
            return 0;
        }
    }
    cerr << (ll) mx << '\n';
    vector<pll> ev;
    REP (i, 0, n) {
        l[i] %= mx; r[i] %= mx;
        ev.pb({l[i], 1});
        ev.pb({r[i] + 1, -1});
        if (r[i] < l[i]) {
            ev.pb({mx, -1});
            ev.pb({0, 1});
        }
        cerr << l[i] << ' ' << r[i] << '\n';
    }
    sort(ALL(ev));
    ll p = 0, cur = 0;
    for (auto [a, b] : ev) {
        cerr << a << ' ' << b << '\n';
        if (cur > 0) {
            ans += a - p;
        }
        cur += b;
        p = a;
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1112 KB Output is correct
3 Correct 6 ms 1112 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1504 KB Output is correct
17 Correct 57 ms 9808 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 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 357 ms 49608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 489 ms 48896 KB Output is correct
3 Correct 509 ms 48960 KB Output is correct
4 Correct 476 ms 48896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 489 ms 48896 KB Output is correct
3 Correct 509 ms 48960 KB Output is correct
4 Correct 476 ms 48896 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 513 ms 48940 KB Output is correct
7 Correct 475 ms 48952 KB Output is correct
8 Correct 493 ms 49024 KB Output is correct
9 Correct 564 ms 48900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 489 ms 48896 KB Output is correct
3 Correct 509 ms 48960 KB Output is correct
4 Correct 476 ms 48896 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 47 ms 6212 KB Output is correct
7 Correct 58 ms 6144 KB Output is correct
8 Correct 46 ms 6052 KB Output is correct
9 Correct 51 ms 6076 KB Output is correct
10 Correct 55 ms 6080 KB Output is correct
11 Correct 54 ms 6112 KB Output is correct
12 Correct 48 ms 6068 KB Output is correct
13 Correct 64 ms 6056 KB Output is correct
14 Correct 53 ms 6084 KB Output is correct
15 Correct 59 ms 6040 KB Output is correct
16 Correct 67 ms 6084 KB Output is correct
17 Correct 48 ms 6036 KB Output is correct
18 Correct 513 ms 48844 KB Output is correct
19 Correct 623 ms 48952 KB Output is correct
20 Correct 620 ms 48872 KB Output is correct
21 Correct 56 ms 6072 KB Output is correct
22 Correct 49 ms 6080 KB Output is correct
23 Correct 156 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 63 ms 6040 KB Output is correct
3 Correct 57 ms 6056 KB Output is correct
4 Correct 640 ms 48952 KB Output is correct
5 Correct 67 ms 6100 KB Output is correct
6 Correct 53 ms 6092 KB Output is correct
7 Correct 68 ms 6144 KB Output is correct
8 Correct 69 ms 6128 KB Output is correct
9 Correct 63 ms 6124 KB Output is correct
10 Correct 66 ms 6032 KB Output is correct
11 Correct 63 ms 6060 KB Output is correct
12 Correct 53 ms 6136 KB Output is correct
13 Correct 64 ms 6112 KB Output is correct
14 Correct 653 ms 48876 KB Output is correct
15 Correct 54 ms 6128 KB Output is correct
16 Correct 555 ms 48944 KB Output is correct
17 Correct 527 ms 48948 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1112 KB Output is correct
3 Correct 6 ms 1112 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1504 KB Output is correct
17 Correct 57 ms 9808 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 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 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 357 ms 49608 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 489 ms 48896 KB Output is correct
31 Correct 509 ms 48960 KB Output is correct
32 Correct 476 ms 48896 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 513 ms 48940 KB Output is correct
35 Correct 475 ms 48952 KB Output is correct
36 Correct 493 ms 49024 KB Output is correct
37 Correct 564 ms 48900 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 47 ms 6212 KB Output is correct
40 Correct 58 ms 6144 KB Output is correct
41 Correct 46 ms 6052 KB Output is correct
42 Correct 51 ms 6076 KB Output is correct
43 Correct 55 ms 6080 KB Output is correct
44 Correct 54 ms 6112 KB Output is correct
45 Correct 48 ms 6068 KB Output is correct
46 Correct 64 ms 6056 KB Output is correct
47 Correct 53 ms 6084 KB Output is correct
48 Correct 59 ms 6040 KB Output is correct
49 Correct 67 ms 6084 KB Output is correct
50 Correct 48 ms 6036 KB Output is correct
51 Correct 513 ms 48844 KB Output is correct
52 Correct 623 ms 48952 KB Output is correct
53 Correct 620 ms 48872 KB Output is correct
54 Correct 56 ms 6072 KB Output is correct
55 Correct 49 ms 6080 KB Output is correct
56 Correct 156 ms 22220 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 63 ms 6040 KB Output is correct
59 Correct 57 ms 6056 KB Output is correct
60 Correct 640 ms 48952 KB Output is correct
61 Correct 67 ms 6100 KB Output is correct
62 Correct 53 ms 6092 KB Output is correct
63 Correct 68 ms 6144 KB Output is correct
64 Correct 69 ms 6128 KB Output is correct
65 Correct 63 ms 6124 KB Output is correct
66 Correct 66 ms 6032 KB Output is correct
67 Correct 63 ms 6060 KB Output is correct
68 Correct 53 ms 6136 KB Output is correct
69 Correct 64 ms 6112 KB Output is correct
70 Correct 653 ms 48876 KB Output is correct
71 Correct 54 ms 6128 KB Output is correct
72 Correct 555 ms 48944 KB Output is correct
73 Correct 527 ms 48948 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 328 KB Output is correct
77 Correct 1 ms 332 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 5 ms 1500 KB Output is correct
80 Correct 649 ms 68252 KB Output is correct
81 Correct 682 ms 68204 KB Output is correct
82 Correct 600 ms 68116 KB Output is correct
83 Correct 607 ms 68300 KB Output is correct
84 Correct 603 ms 68180 KB Output is correct
85 Correct 611 ms 68184 KB Output is correct
86 Correct 151 ms 34752 KB Output is correct
87 Correct 1 ms 332 KB Output is correct