Submission #683682

# Submission time Handle Problem Language Result Execution time Memory
683682 2023-01-19T05:25:52 Z Nursik Strange Device (APIO19_strange_device) C++17
100 / 100
501 ms 68968 KB
#include <stdio.h>
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
#define bug cout << "bug\n";

const ll maxn = 1e6 + 5, maxm = 2e2 + 1;
const ll mod = 1e9 + 7, inf = 1e9, block = 550, hb = 126067, base = 1000050017,
         biginf = 5e18;
const ld eps = 1e-15;
using namespace std;

int n;
ll a, b, p;
ll l[maxn], r[maxn];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> a >> b;
    a = a / gcd(a, b + 1);
    if (a > 1e18 / b){
        p = 1e18;
    }
    else{
        p = a * b;
    }
    vector<pair<ll, ll>> v;
    for (int i = 1; i <= n; ++i){
        cin >> l[i] >> r[i];
        ll x = l[i] % p;
        ll y = r[i] % p;
        if (r[i] - l[i] + 1 >= p){
            cout << p;
            exit(0);
        }
        if (x <= y){
            v.pb(mp(x, y));
        }
        else{
            v.pb(mp(x, p - 1));
            v.pb(mp(0, y));
        }
    }
    sort(v.begin(), v.end());
    ll ans = 0, nxt = -1;
    for (auto it : v){
        ll lf = it.f, rg = it.s;
        if (nxt < lf){
            ans += rg - lf + 1;
            nxt = rg;
        }
        else if (nxt <= rg){
            ans += rg - nxt;
            nxt = rg;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 980 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 980 KB Output is correct
17 Correct 43 ms 3828 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 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 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 288 ms 32092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 421 ms 31984 KB Output is correct
3 Correct 392 ms 31832 KB Output is correct
4 Correct 400 ms 31780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 421 ms 31984 KB Output is correct
3 Correct 392 ms 31832 KB Output is correct
4 Correct 400 ms 31780 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 387 ms 31824 KB Output is correct
7 Correct 397 ms 31868 KB Output is correct
8 Correct 374 ms 31768 KB Output is correct
9 Correct 418 ms 31800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 421 ms 31984 KB Output is correct
3 Correct 392 ms 31832 KB Output is correct
4 Correct 400 ms 31780 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 40 ms 3784 KB Output is correct
7 Correct 39 ms 3784 KB Output is correct
8 Correct 40 ms 3736 KB Output is correct
9 Correct 40 ms 3796 KB Output is correct
10 Correct 41 ms 3756 KB Output is correct
11 Correct 45 ms 3828 KB Output is correct
12 Correct 40 ms 3784 KB Output is correct
13 Correct 41 ms 3784 KB Output is correct
14 Correct 37 ms 3784 KB Output is correct
15 Correct 41 ms 3808 KB Output is correct
16 Correct 41 ms 3744 KB Output is correct
17 Correct 39 ms 3776 KB Output is correct
18 Correct 386 ms 32164 KB Output is correct
19 Correct 368 ms 31960 KB Output is correct
20 Correct 415 ms 31740 KB Output is correct
21 Correct 40 ms 3560 KB Output is correct
22 Correct 35 ms 3520 KB Output is correct
23 Correct 126 ms 12652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 41 ms 3536 KB Output is correct
3 Correct 41 ms 3496 KB Output is correct
4 Correct 443 ms 31728 KB Output is correct
5 Correct 40 ms 3536 KB Output is correct
6 Correct 38 ms 3584 KB Output is correct
7 Correct 43 ms 3588 KB Output is correct
8 Correct 41 ms 3536 KB Output is correct
9 Correct 41 ms 3504 KB Output is correct
10 Correct 39 ms 3536 KB Output is correct
11 Correct 41 ms 3576 KB Output is correct
12 Correct 34 ms 3548 KB Output is correct
13 Correct 39 ms 3536 KB Output is correct
14 Correct 405 ms 31704 KB Output is correct
15 Correct 40 ms 3536 KB Output is correct
16 Correct 368 ms 31700 KB Output is correct
17 Correct 387 ms 31744 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 5 ms 980 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 7 ms 980 KB Output is correct
17 Correct 43 ms 3828 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 288 ms 32092 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 421 ms 31984 KB Output is correct
31 Correct 392 ms 31832 KB Output is correct
32 Correct 400 ms 31780 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 387 ms 31824 KB Output is correct
35 Correct 397 ms 31868 KB Output is correct
36 Correct 374 ms 31768 KB Output is correct
37 Correct 418 ms 31800 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 40 ms 3784 KB Output is correct
40 Correct 39 ms 3784 KB Output is correct
41 Correct 40 ms 3736 KB Output is correct
42 Correct 40 ms 3796 KB Output is correct
43 Correct 41 ms 3756 KB Output is correct
44 Correct 45 ms 3828 KB Output is correct
45 Correct 40 ms 3784 KB Output is correct
46 Correct 41 ms 3784 KB Output is correct
47 Correct 37 ms 3784 KB Output is correct
48 Correct 41 ms 3808 KB Output is correct
49 Correct 41 ms 3744 KB Output is correct
50 Correct 39 ms 3776 KB Output is correct
51 Correct 386 ms 32164 KB Output is correct
52 Correct 368 ms 31960 KB Output is correct
53 Correct 415 ms 31740 KB Output is correct
54 Correct 40 ms 3560 KB Output is correct
55 Correct 35 ms 3520 KB Output is correct
56 Correct 126 ms 12652 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 41 ms 3536 KB Output is correct
59 Correct 41 ms 3496 KB Output is correct
60 Correct 443 ms 31728 KB Output is correct
61 Correct 40 ms 3536 KB Output is correct
62 Correct 38 ms 3584 KB Output is correct
63 Correct 43 ms 3588 KB Output is correct
64 Correct 41 ms 3536 KB Output is correct
65 Correct 41 ms 3504 KB Output is correct
66 Correct 39 ms 3536 KB Output is correct
67 Correct 41 ms 3576 KB Output is correct
68 Correct 34 ms 3548 KB Output is correct
69 Correct 39 ms 3536 KB Output is correct
70 Correct 405 ms 31704 KB Output is correct
71 Correct 40 ms 3536 KB Output is correct
72 Correct 368 ms 31700 KB Output is correct
73 Correct 387 ms 31744 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 324 KB Output is correct
77 Correct 0 ms 328 KB Output is correct
78 Correct 0 ms 324 KB Output is correct
79 Correct 4 ms 1236 KB Output is correct
80 Correct 501 ms 68900 KB Output is correct
81 Correct 495 ms 68904 KB Output is correct
82 Correct 441 ms 68968 KB Output is correct
83 Correct 443 ms 68920 KB Output is correct
84 Correct 446 ms 68920 KB Output is correct
85 Correct 442 ms 68696 KB Output is correct
86 Correct 132 ms 23624 KB Output is correct
87 Correct 1 ms 332 KB Output is correct