Submission #635820

# Submission time Handle Problem Language Result Execution time Memory
635820 2022-08-27T04:48:06 Z PoonYaPat Strange Device (APIO19_strange_device) C++14
100 / 100
468 ms 53336 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

ll n,A,B,mod,ans;
vector<pll> v;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>A>>B;
    A=A/__gcd(A,B+1);

    if (A>2e18/B || A>2e18/B) mod=2e18;
    else mod=A*B;

    while (n--) {
        ll l,r;
        cin>>l>>r;
        if (r-l+1>=mod) {
            cout<<mod;
            return 0;
        }
        l%=mod;
        r%=mod;

        if (l<=r) v.push_back(pll(l,r));
        else v.push_back(pll(l,mod-1)), v.push_back(pll(0,r));
    }

    sort(v.begin(),v.end());
    ll l=v[0].first, r=v[0].second;

    for (auto s : v) {
        if (s.first<=r) {
            r=max(r,s.second);
        } else {
            ans+=r-l+1;
            l=s.first; r=s.second;
        }
    }
    ans+=r-l+1;
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Correct 5 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 212 KB Output is correct
9 Correct 1 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 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 5 ms 1052 KB Output is correct
17 Correct 48 ms 5612 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 0 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 297 ms 41212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 379 ms 16812 KB Output is correct
3 Correct 373 ms 16972 KB Output is correct
4 Correct 378 ms 16832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 379 ms 16812 KB Output is correct
3 Correct 373 ms 16972 KB Output is correct
4 Correct 378 ms 16832 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 365 ms 16804 KB Output is correct
7 Correct 387 ms 16776 KB Output is correct
8 Correct 363 ms 16812 KB Output is correct
9 Correct 426 ms 16808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 379 ms 16812 KB Output is correct
3 Correct 373 ms 16972 KB Output is correct
4 Correct 378 ms 16832 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 40 ms 2440 KB Output is correct
7 Correct 42 ms 5616 KB Output is correct
8 Correct 38 ms 5700 KB Output is correct
9 Correct 39 ms 5628 KB Output is correct
10 Correct 42 ms 5700 KB Output is correct
11 Correct 47 ms 5708 KB Output is correct
12 Correct 40 ms 5608 KB Output is correct
13 Correct 42 ms 5684 KB Output is correct
14 Correct 39 ms 5668 KB Output is correct
15 Correct 44 ms 5628 KB Output is correct
16 Correct 45 ms 5628 KB Output is correct
17 Correct 53 ms 5680 KB Output is correct
18 Correct 400 ms 53224 KB Output is correct
19 Correct 403 ms 53300 KB Output is correct
20 Correct 457 ms 53256 KB Output is correct
21 Correct 40 ms 5696 KB Output is correct
22 Correct 37 ms 5672 KB Output is correct
23 Correct 162 ms 18416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 41 ms 2540 KB Output is correct
3 Correct 46 ms 2556 KB Output is correct
4 Correct 459 ms 16980 KB Output is correct
5 Correct 39 ms 2640 KB Output is correct
6 Correct 50 ms 2576 KB Output is correct
7 Correct 41 ms 2520 KB Output is correct
8 Correct 41 ms 2536 KB Output is correct
9 Correct 38 ms 2524 KB Output is correct
10 Correct 39 ms 2640 KB Output is correct
11 Correct 40 ms 2532 KB Output is correct
12 Correct 37 ms 2624 KB Output is correct
13 Correct 43 ms 2624 KB Output is correct
14 Correct 404 ms 17016 KB Output is correct
15 Correct 40 ms 2524 KB Output is correct
16 Correct 372 ms 16856 KB Output is correct
17 Correct 378 ms 16840 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
3 Correct 5 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 212 KB Output is correct
9 Correct 1 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 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 5 ms 1052 KB Output is correct
17 Correct 48 ms 5612 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 0 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 297 ms 41212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 379 ms 16812 KB Output is correct
31 Correct 373 ms 16972 KB Output is correct
32 Correct 378 ms 16832 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 365 ms 16804 KB Output is correct
35 Correct 387 ms 16776 KB Output is correct
36 Correct 363 ms 16812 KB Output is correct
37 Correct 426 ms 16808 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 40 ms 2440 KB Output is correct
40 Correct 42 ms 5616 KB Output is correct
41 Correct 38 ms 5700 KB Output is correct
42 Correct 39 ms 5628 KB Output is correct
43 Correct 42 ms 5700 KB Output is correct
44 Correct 47 ms 5708 KB Output is correct
45 Correct 40 ms 5608 KB Output is correct
46 Correct 42 ms 5684 KB Output is correct
47 Correct 39 ms 5668 KB Output is correct
48 Correct 44 ms 5628 KB Output is correct
49 Correct 45 ms 5628 KB Output is correct
50 Correct 53 ms 5680 KB Output is correct
51 Correct 400 ms 53224 KB Output is correct
52 Correct 403 ms 53300 KB Output is correct
53 Correct 457 ms 53256 KB Output is correct
54 Correct 40 ms 5696 KB Output is correct
55 Correct 37 ms 5672 KB Output is correct
56 Correct 162 ms 18416 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 41 ms 2540 KB Output is correct
59 Correct 46 ms 2556 KB Output is correct
60 Correct 459 ms 16980 KB Output is correct
61 Correct 39 ms 2640 KB Output is correct
62 Correct 50 ms 2576 KB Output is correct
63 Correct 41 ms 2520 KB Output is correct
64 Correct 41 ms 2536 KB Output is correct
65 Correct 38 ms 2524 KB Output is correct
66 Correct 39 ms 2640 KB Output is correct
67 Correct 40 ms 2532 KB Output is correct
68 Correct 37 ms 2624 KB Output is correct
69 Correct 43 ms 2624 KB Output is correct
70 Correct 404 ms 17016 KB Output is correct
71 Correct 40 ms 2524 KB Output is correct
72 Correct 372 ms 16856 KB Output is correct
73 Correct 378 ms 16840 KB Output is correct
74 Correct 1 ms 320 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 316 KB Output is correct
79 Correct 4 ms 980 KB Output is correct
80 Correct 468 ms 53336 KB Output is correct
81 Correct 467 ms 53284 KB Output is correct
82 Correct 429 ms 53184 KB Output is correct
83 Correct 434 ms 53216 KB Output is correct
84 Correct 446 ms 53316 KB Output is correct
85 Correct 437 ms 53264 KB Output is correct
86 Correct 128 ms 18436 KB Output is correct
87 Correct 1 ms 256 KB Output is correct