Submission #729717

# Submission time Handle Problem Language Result Execution time Memory
729717 2023-04-24T11:46:21 Z danikoynov Strange Device (APIO19_strange_device) C++14
100 / 100
1609 ms 49264 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll maxn = 1e6 + 10;

ll n;
ll l[maxn], r[maxn];
ll A, B;

struct poll
{
    ll x, t;
    poll(ll _x = 0, ll _t = 0)
    {
        x = _x;
        t = _t;
    }

    bool operator < (const poll &p) const
    {
        if (x == p.x)
            return t < p.t;
        return x < p.x;
    }
};


vector < poll > vec;
void add_segment(ll l, ll r)
{

    vec.push_back(poll(l, 1));
    vec.push_back(poll(r + 1, -1));
}
void solve()
{
    cin >> n >> A >> B;

    for (ll i = 1; i <= n; i ++)
    {
        cin >> l[i] >> r[i];
    }
    ll g = __gcd(A, B + 1);
    /// period is A * B / g
    if ((double)(1e18) / (double)(A) < (double)(B) / (double)(g))
    {
        ll ans = 0;
        for (ll i = 1; i <= n; i ++)
        {
            ans = ans + (r[i] - l[i] + 1);
        }
        cout << ans << endl;
        return;
    }

    long long period = A * B / g;
    for (ll i = 1; i <= n; i ++)
    {


            if (r[i] - l[i] + 1 >= period)
            {
                cout << period << endl;
                return;
            }

            ll x = l[i] % period, y = r[i] % period;
            if (x <= y)
            {
                add_segment(x, y);
            }
            else
            {
                add_segment(0, y);
                add_segment(x, period - 1);
            }

    }

    sort(vec.begin(), vec.end());
    ll ans = 0, cnt = 1;
    for (ll i = 1; i < vec.size(); i ++)
    {
        ///cout << i << " :: " << cnt << " " << vec[i].x << endl;
        if (cnt > 0)
            ans = ans + vec[i].x - vec[i - 1].x;
        cnt += vec[i].t;
    }
    cout << ans << endl;
}


int main()
{
    solve();
    return 0;
}
/**
1  10000 3312452154131231
1 1
*/

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:92:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<poll>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for (ll i = 1; i < vec.size(); i ++)
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 1036 KB Output is correct
3 Correct 16 ms 1104 KB Output is correct
4 Correct 0 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 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 1104 KB Output is correct
17 Correct 161 ms 6156 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 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 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1012 ms 48864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1406 ms 48996 KB Output is correct
3 Correct 1436 ms 49008 KB Output is correct
4 Correct 1446 ms 48960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1406 ms 48996 KB Output is correct
3 Correct 1436 ms 49008 KB Output is correct
4 Correct 1446 ms 48960 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1482 ms 49052 KB Output is correct
7 Correct 1403 ms 48944 KB Output is correct
8 Correct 1424 ms 49064 KB Output is correct
9 Correct 1536 ms 49020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1406 ms 48996 KB Output is correct
3 Correct 1436 ms 49008 KB Output is correct
4 Correct 1446 ms 48960 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 146 ms 6248 KB Output is correct
7 Correct 139 ms 6176 KB Output is correct
8 Correct 134 ms 6120 KB Output is correct
9 Correct 139 ms 6168 KB Output is correct
10 Correct 134 ms 6224 KB Output is correct
11 Correct 144 ms 6152 KB Output is correct
12 Correct 138 ms 6232 KB Output is correct
13 Correct 141 ms 6132 KB Output is correct
14 Correct 138 ms 6164 KB Output is correct
15 Correct 146 ms 6196 KB Output is correct
16 Correct 144 ms 6216 KB Output is correct
17 Correct 144 ms 6152 KB Output is correct
18 Correct 1435 ms 49064 KB Output is correct
19 Correct 1425 ms 49060 KB Output is correct
20 Correct 1561 ms 49120 KB Output is correct
21 Correct 152 ms 6204 KB Output is correct
22 Correct 136 ms 6164 KB Output is correct
23 Correct 451 ms 22600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 138 ms 6088 KB Output is correct
3 Correct 140 ms 6040 KB Output is correct
4 Correct 1597 ms 48932 KB Output is correct
5 Correct 143 ms 6076 KB Output is correct
6 Correct 147 ms 6084 KB Output is correct
7 Correct 148 ms 6076 KB Output is correct
8 Correct 144 ms 6064 KB Output is correct
9 Correct 157 ms 6080 KB Output is correct
10 Correct 146 ms 6004 KB Output is correct
11 Correct 137 ms 6132 KB Output is correct
12 Correct 134 ms 6048 KB Output is correct
13 Correct 158 ms 6212 KB Output is correct
14 Correct 1522 ms 49148 KB Output is correct
15 Correct 168 ms 6132 KB Output is correct
16 Correct 1361 ms 49056 KB Output is correct
17 Correct 1432 ms 49068 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 15 ms 1036 KB Output is correct
3 Correct 16 ms 1104 KB Output is correct
4 Correct 0 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 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 1104 KB Output is correct
17 Correct 161 ms 6156 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 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 0 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1012 ms 48864 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1406 ms 48996 KB Output is correct
31 Correct 1436 ms 49008 KB Output is correct
32 Correct 1446 ms 48960 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1482 ms 49052 KB Output is correct
35 Correct 1403 ms 48944 KB Output is correct
36 Correct 1424 ms 49064 KB Output is correct
37 Correct 1536 ms 49020 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 146 ms 6248 KB Output is correct
40 Correct 139 ms 6176 KB Output is correct
41 Correct 134 ms 6120 KB Output is correct
42 Correct 139 ms 6168 KB Output is correct
43 Correct 134 ms 6224 KB Output is correct
44 Correct 144 ms 6152 KB Output is correct
45 Correct 138 ms 6232 KB Output is correct
46 Correct 141 ms 6132 KB Output is correct
47 Correct 138 ms 6164 KB Output is correct
48 Correct 146 ms 6196 KB Output is correct
49 Correct 144 ms 6216 KB Output is correct
50 Correct 144 ms 6152 KB Output is correct
51 Correct 1435 ms 49064 KB Output is correct
52 Correct 1425 ms 49060 KB Output is correct
53 Correct 1561 ms 49120 KB Output is correct
54 Correct 152 ms 6204 KB Output is correct
55 Correct 136 ms 6164 KB Output is correct
56 Correct 451 ms 22600 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 138 ms 6088 KB Output is correct
59 Correct 140 ms 6040 KB Output is correct
60 Correct 1597 ms 48932 KB Output is correct
61 Correct 143 ms 6076 KB Output is correct
62 Correct 147 ms 6084 KB Output is correct
63 Correct 148 ms 6076 KB Output is correct
64 Correct 144 ms 6064 KB Output is correct
65 Correct 157 ms 6080 KB Output is correct
66 Correct 146 ms 6004 KB Output is correct
67 Correct 137 ms 6132 KB Output is correct
68 Correct 134 ms 6048 KB Output is correct
69 Correct 158 ms 6212 KB Output is correct
70 Correct 1522 ms 49148 KB Output is correct
71 Correct 168 ms 6132 KB Output is correct
72 Correct 1361 ms 49056 KB Output is correct
73 Correct 1432 ms 49068 KB Output is correct
74 Correct 1 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 1 ms 308 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 14 ms 1232 KB Output is correct
80 Correct 1609 ms 49084 KB Output is correct
81 Correct 1552 ms 49184 KB Output is correct
82 Correct 1552 ms 49088 KB Output is correct
83 Correct 1538 ms 49000 KB Output is correct
84 Correct 1504 ms 49012 KB Output is correct
85 Correct 1533 ms 49264 KB Output is correct
86 Correct 436 ms 22216 KB Output is correct
87 Correct 1 ms 212 KB Output is correct