Submission #785879

# Submission time Handle Problem Language Result Execution time Memory
785879 2023-07-17T17:35:03 Z aykhn Strange Device (APIO19_strange_device) C++14
100 / 100
607 ms 115840 KB
#include <bits/stdc++.h>

// author: aykhn

using namespace std;

typedef long long ll;

#define TC int t; cin >> t; while (t--) _();
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define mpr make_pair
#define eb emplace_back
#define new int32_t
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define int ll
#define ins insert
#define inf 0x3F3F3F3F
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount

__int128 n, a, b;

/*int x(int i)
{
    return (i + i/b) % a;
}
int y(int i)
{
    return i % b;
}*/
__int128 read() {
    __int128 x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
void print(__int128 x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
bool cmp(__int128 x, __int128 y) { return x >= y; }

new main()
{
    n = read();
    a = read();
    b = read();

    __int128 x = a/__gcd(a, b + 1) * b;

    set<pair<__int128, __int128>> s;

    for (__int128 i = 0; i < n; i++)
    {
        __int128 a, b;
        a = read();
        b = read();

        if (b - a + 1 >= x)
        {
            s.ins(mpr(1, x));
        }
        else
        {
            __int128 l = a % x + 1;
            __int128 r = b % x + 1;

            if (l <= r)
            {
                s.ins(mpr(l, r));
            }
            else
            {
                s.ins(mpr(l, x));
                s.ins(mpr(1, r));
            }
        }
    }

    set<pair<__int128, __int128>> nw;

    while (s.size() > 1)
    {
        auto it = s.begin();
        pair<__int128, __int128> a = *it;
        it++;
        pair<__int128, __int128> b = *it;

        if (max(a.fi, b.fi) <= min(a.se, b.se))
        {
            s.erase(s.begin());
            s.erase(s.begin());
            s.ins(mpr(min(a.fi, b.fi), max(a.se, b.se)));
        }
        else
        {
            s.erase(s.begin());
            nw.ins(a);
        }
    }

    nw.ins(*s.begin());

    __int128 res = 0;

    for (pii a : nw)
    {
        res += a.se - a.fi + 1;
    }

    print(res);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 4 ms 1364 KB Output is correct
3 Correct 4 ms 1428 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 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 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 1452 KB Output is correct
17 Correct 44 ms 11708 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 178 ms 1944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 491 ms 81896 KB Output is correct
3 Correct 488 ms 81900 KB Output is correct
4 Correct 519 ms 81860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 491 ms 81896 KB Output is correct
3 Correct 488 ms 81900 KB Output is correct
4 Correct 519 ms 81860 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 485 ms 81868 KB Output is correct
7 Correct 496 ms 81888 KB Output is correct
8 Correct 488 ms 79732 KB Output is correct
9 Correct 538 ms 79656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 491 ms 81896 KB Output is correct
3 Correct 488 ms 81900 KB Output is correct
4 Correct 519 ms 81860 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 44 ms 9164 KB Output is correct
7 Correct 40 ms 9252 KB Output is correct
8 Correct 39 ms 9232 KB Output is correct
9 Correct 45 ms 9212 KB Output is correct
10 Correct 39 ms 9236 KB Output is correct
11 Correct 42 ms 9216 KB Output is correct
12 Correct 44 ms 9260 KB Output is correct
13 Correct 44 ms 9156 KB Output is correct
14 Correct 39 ms 9240 KB Output is correct
15 Correct 47 ms 9164 KB Output is correct
16 Correct 46 ms 9240 KB Output is correct
17 Correct 56 ms 9472 KB Output is correct
18 Correct 476 ms 79692 KB Output is correct
19 Correct 510 ms 79816 KB Output is correct
20 Correct 543 ms 79724 KB Output is correct
21 Correct 40 ms 9164 KB Output is correct
22 Correct 42 ms 9260 KB Output is correct
23 Correct 51 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 47 ms 9152 KB Output is correct
3 Correct 50 ms 9160 KB Output is correct
4 Correct 507 ms 79724 KB Output is correct
5 Correct 46 ms 9288 KB Output is correct
6 Correct 48 ms 9232 KB Output is correct
7 Correct 49 ms 9236 KB Output is correct
8 Correct 47 ms 9252 KB Output is correct
9 Correct 47 ms 9164 KB Output is correct
10 Correct 41 ms 9220 KB Output is correct
11 Correct 42 ms 9256 KB Output is correct
12 Correct 43 ms 9212 KB Output is correct
13 Correct 50 ms 9252 KB Output is correct
14 Correct 544 ms 79724 KB Output is correct
15 Correct 40 ms 9260 KB Output is correct
16 Correct 467 ms 79660 KB Output is correct
17 Correct 469 ms 79524 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 4 ms 1364 KB Output is correct
3 Correct 4 ms 1428 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 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 296 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 1452 KB Output is correct
17 Correct 44 ms 11708 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 0 ms 216 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 178 ms 1944 KB Output is correct
29 Correct 1 ms 288 KB Output is correct
30 Correct 491 ms 81896 KB Output is correct
31 Correct 488 ms 81900 KB Output is correct
32 Correct 519 ms 81860 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 485 ms 81868 KB Output is correct
35 Correct 496 ms 81888 KB Output is correct
36 Correct 488 ms 79732 KB Output is correct
37 Correct 538 ms 79656 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 44 ms 9164 KB Output is correct
40 Correct 40 ms 9252 KB Output is correct
41 Correct 39 ms 9232 KB Output is correct
42 Correct 45 ms 9212 KB Output is correct
43 Correct 39 ms 9236 KB Output is correct
44 Correct 42 ms 9216 KB Output is correct
45 Correct 44 ms 9260 KB Output is correct
46 Correct 44 ms 9156 KB Output is correct
47 Correct 39 ms 9240 KB Output is correct
48 Correct 47 ms 9164 KB Output is correct
49 Correct 46 ms 9240 KB Output is correct
50 Correct 56 ms 9472 KB Output is correct
51 Correct 476 ms 79692 KB Output is correct
52 Correct 510 ms 79816 KB Output is correct
53 Correct 543 ms 79724 KB Output is correct
54 Correct 40 ms 9164 KB Output is correct
55 Correct 42 ms 9260 KB Output is correct
56 Correct 51 ms 1436 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 47 ms 9152 KB Output is correct
59 Correct 50 ms 9160 KB Output is correct
60 Correct 507 ms 79724 KB Output is correct
61 Correct 46 ms 9288 KB Output is correct
62 Correct 48 ms 9232 KB Output is correct
63 Correct 49 ms 9236 KB Output is correct
64 Correct 47 ms 9252 KB Output is correct
65 Correct 47 ms 9164 KB Output is correct
66 Correct 41 ms 9220 KB Output is correct
67 Correct 42 ms 9256 KB Output is correct
68 Correct 43 ms 9212 KB Output is correct
69 Correct 50 ms 9252 KB Output is correct
70 Correct 544 ms 79724 KB Output is correct
71 Correct 40 ms 9260 KB Output is correct
72 Correct 467 ms 79660 KB Output is correct
73 Correct 469 ms 79524 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 6 ms 1336 KB Output is correct
80 Correct 549 ms 115752 KB Output is correct
81 Correct 521 ms 115840 KB Output is correct
82 Correct 607 ms 115660 KB Output is correct
83 Correct 596 ms 115752 KB Output is correct
84 Correct 566 ms 115800 KB Output is correct
85 Correct 536 ms 115764 KB Output is correct
86 Correct 52 ms 12804 KB Output is correct
87 Correct 1 ms 212 KB Output is correct