Submission #612379

# Submission time Handle Problem Language Result Execution time Memory
612379 2022-07-29T13:44:09 Z Theo830 Strange Device (APIO19_strange_device) C++17
100 / 100
478 ms 53380 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,A,B;
    cin>>n>>A>>B;
    ll c = B;
    ll g = __gcd(B+1,A);
    A /= g;
    ll maxi = 1e18 + 105;
    if(maxi / c < A){
        c = maxi;
    }
    else{
        c *= A;
    }
    vector<ii>ex;
    f(i,0,n){
        ll l,r;
        cin>>l>>r;
        if(r - l + 1 >= c){
            ex.pb(ii(0,c - 1));
        }
        else{
            l %= c;
            r %= c;
            if(l <= r){
                ex.pb(ii(l,r));
            }
            else{
                ex.pb(ii(l,c-1));
                ex.pb(ii(0,r));
            }
        }
    }
    sort(all(ex));
    ll l = ex[0].F,r = ex[0].S;
    ll ans = 0;
    for(auto x:ex){
        if(x.F <= r){
            r = max(r,x.S);
        }
        else{
            ans += r - l + 1;
            l = x.F,r = x.S;
        }
    }
    ans += r - l + 1;
    cout<<ans<<"\n";
}
# 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 4 ms 976 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 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 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 984 KB Output is correct
17 Correct 47 ms 5636 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 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 327 ms 41260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 407 ms 16816 KB Output is correct
3 Correct 371 ms 16816 KB Output is correct
4 Correct 371 ms 17000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 407 ms 16816 KB Output is correct
3 Correct 371 ms 16816 KB Output is correct
4 Correct 371 ms 17000 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 370 ms 16836 KB Output is correct
7 Correct 388 ms 16832 KB Output is correct
8 Correct 370 ms 16832 KB Output is correct
9 Correct 400 ms 16784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 407 ms 16816 KB Output is correct
3 Correct 371 ms 16816 KB Output is correct
4 Correct 371 ms 17000 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 36 ms 2512 KB Output is correct
7 Correct 39 ms 2476 KB Output is correct
8 Correct 37 ms 2528 KB Output is correct
9 Correct 38 ms 2512 KB Output is correct
10 Correct 43 ms 2512 KB Output is correct
11 Correct 38 ms 2512 KB Output is correct
12 Correct 36 ms 2464 KB Output is correct
13 Correct 41 ms 2496 KB Output is correct
14 Correct 40 ms 2492 KB Output is correct
15 Correct 42 ms 2428 KB Output is correct
16 Correct 45 ms 5620 KB Output is correct
17 Correct 52 ms 5756 KB Output is correct
18 Correct 414 ms 53308 KB Output is correct
19 Correct 387 ms 53272 KB Output is correct
20 Correct 445 ms 53300 KB Output is correct
21 Correct 43 ms 5636 KB Output is correct
22 Correct 36 ms 5696 KB Output is correct
23 Correct 121 ms 18444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 43 ms 2512 KB Output is correct
3 Correct 40 ms 2420 KB Output is correct
4 Correct 446 ms 16876 KB Output is correct
5 Correct 39 ms 2512 KB Output is correct
6 Correct 39 ms 2488 KB Output is correct
7 Correct 40 ms 2384 KB Output is correct
8 Correct 42 ms 2408 KB Output is correct
9 Correct 40 ms 2456 KB Output is correct
10 Correct 42 ms 2512 KB Output is correct
11 Correct 42 ms 2412 KB Output is correct
12 Correct 35 ms 2512 KB Output is correct
13 Correct 40 ms 2460 KB Output is correct
14 Correct 422 ms 16860 KB Output is correct
15 Correct 44 ms 5744 KB Output is correct
16 Correct 409 ms 53284 KB Output is correct
17 Correct 414 ms 53272 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 4 ms 600 KB Output is correct
3 Correct 4 ms 976 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 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 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 984 KB Output is correct
17 Correct 47 ms 5636 KB Output is correct
18 Correct 1 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 1 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 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 327 ms 41260 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 407 ms 16816 KB Output is correct
31 Correct 371 ms 16816 KB Output is correct
32 Correct 371 ms 17000 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 370 ms 16836 KB Output is correct
35 Correct 388 ms 16832 KB Output is correct
36 Correct 370 ms 16832 KB Output is correct
37 Correct 400 ms 16784 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 36 ms 2512 KB Output is correct
40 Correct 39 ms 2476 KB Output is correct
41 Correct 37 ms 2528 KB Output is correct
42 Correct 38 ms 2512 KB Output is correct
43 Correct 43 ms 2512 KB Output is correct
44 Correct 38 ms 2512 KB Output is correct
45 Correct 36 ms 2464 KB Output is correct
46 Correct 41 ms 2496 KB Output is correct
47 Correct 40 ms 2492 KB Output is correct
48 Correct 42 ms 2428 KB Output is correct
49 Correct 45 ms 5620 KB Output is correct
50 Correct 52 ms 5756 KB Output is correct
51 Correct 414 ms 53308 KB Output is correct
52 Correct 387 ms 53272 KB Output is correct
53 Correct 445 ms 53300 KB Output is correct
54 Correct 43 ms 5636 KB Output is correct
55 Correct 36 ms 5696 KB Output is correct
56 Correct 121 ms 18444 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 43 ms 2512 KB Output is correct
59 Correct 40 ms 2420 KB Output is correct
60 Correct 446 ms 16876 KB Output is correct
61 Correct 39 ms 2512 KB Output is correct
62 Correct 39 ms 2488 KB Output is correct
63 Correct 40 ms 2384 KB Output is correct
64 Correct 42 ms 2408 KB Output is correct
65 Correct 40 ms 2456 KB Output is correct
66 Correct 42 ms 2512 KB Output is correct
67 Correct 42 ms 2412 KB Output is correct
68 Correct 35 ms 2512 KB Output is correct
69 Correct 40 ms 2460 KB Output is correct
70 Correct 422 ms 16860 KB Output is correct
71 Correct 44 ms 5744 KB Output is correct
72 Correct 409 ms 53284 KB Output is correct
73 Correct 414 ms 53272 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 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 212 KB Output is correct
79 Correct 5 ms 984 KB Output is correct
80 Correct 478 ms 53372 KB Output is correct
81 Correct 468 ms 53260 KB Output is correct
82 Correct 421 ms 53232 KB Output is correct
83 Correct 449 ms 53296 KB Output is correct
84 Correct 458 ms 53380 KB Output is correct
85 Correct 447 ms 53300 KB Output is correct
86 Correct 138 ms 18488 KB Output is correct
87 Correct 1 ms 212 KB Output is correct