Submission #484579

# Submission time Handle Problem Language Result Execution time Memory
484579 2021-11-04T13:16:33 Z CyberSleeper Strange Device (APIO19_strange_device) C++14
100 / 100
508 ms 53256 KB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define pll         pair<ll, ll>
#define ull         unsigned long long
#define ld          long double
#define pii         pair<ll, ll>
#define nl          '\n'
#define tb          '\t'
#define sp          ' '
using namespace std;

const ll MX=1000001, MOD=998244353, BLOCK=330, INF=1e9+7, INFF=2e18;
const ld ERR=1e-7, pi=3.14159265358979323846;

ll N, A, B, cyc, last=0, GCD;
vector<pll> L;

int main(){
    fastio;
    cin >> N >> A >> B;
    A/=__gcd(A, B+1ll);
    cyc=(INFF+A-1)/A;
    if(B>=cyc)
        cyc=INFF;
    else
        cyc=A*B;
    for(ll i=0, x, y; i<N; i++){
        cin >> x >> y;
        if(y-x+1>=cyc){
            L.pb({0, cyc-1});
        }else{
            x%=cyc;
            y%=cyc;
            if(x<=y)
                L.pb({x, y});
            else{
                L.pb({0, y});
                L.pb({x, cyc-1});
            }
        }
    }
    N=L.size();
    sort(L.begin(), L.end());
    ll ans=0;
    for(auto i:L){
        ll x=i.fi, y=i.se;
        if(y<last)
            continue;
        x=max(last, x);
        ans+=y-x+1;
        last=max(last, y+1);
    }
    cout << ans << nl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 5 ms 976 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 1072 KB Output is correct
17 Correct 41 ms 5692 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 289 ms 18036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 382 ms 17448 KB Output is correct
3 Correct 402 ms 19108 KB Output is correct
4 Correct 368 ms 19108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 382 ms 17448 KB Output is correct
3 Correct 402 ms 19108 KB Output is correct
4 Correct 368 ms 19108 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 373 ms 19036 KB Output is correct
7 Correct 371 ms 19028 KB Output is correct
8 Correct 388 ms 19092 KB Output is correct
9 Correct 442 ms 53116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 382 ms 17448 KB Output is correct
3 Correct 402 ms 19108 KB Output is correct
4 Correct 368 ms 19108 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 39 ms 5692 KB Output is correct
7 Correct 53 ms 5692 KB Output is correct
8 Correct 43 ms 5628 KB Output is correct
9 Correct 38 ms 5696 KB Output is correct
10 Correct 38 ms 5700 KB Output is correct
11 Correct 42 ms 5716 KB Output is correct
12 Correct 37 ms 5700 KB Output is correct
13 Correct 43 ms 5688 KB Output is correct
14 Correct 39 ms 5688 KB Output is correct
15 Correct 41 ms 5636 KB Output is correct
16 Correct 42 ms 5700 KB Output is correct
17 Correct 40 ms 5628 KB Output is correct
18 Correct 396 ms 19120 KB Output is correct
19 Correct 403 ms 18980 KB Output is correct
20 Correct 421 ms 19108 KB Output is correct
21 Correct 56 ms 5692 KB Output is correct
22 Correct 45 ms 5628 KB Output is correct
23 Correct 118 ms 18456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 45 ms 5564 KB Output is correct
3 Correct 43 ms 5672 KB Output is correct
4 Correct 497 ms 18936 KB Output is correct
5 Correct 40 ms 5692 KB Output is correct
6 Correct 40 ms 5632 KB Output is correct
7 Correct 44 ms 5708 KB Output is correct
8 Correct 46 ms 5696 KB Output is correct
9 Correct 44 ms 5608 KB Output is correct
10 Correct 48 ms 5688 KB Output is correct
11 Correct 40 ms 5692 KB Output is correct
12 Correct 35 ms 5696 KB Output is correct
13 Correct 43 ms 5620 KB Output is correct
14 Correct 417 ms 18856 KB Output is correct
15 Correct 41 ms 5688 KB Output is correct
16 Correct 442 ms 53180 KB Output is correct
17 Correct 446 ms 53148 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 5 ms 976 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 0 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 4 ms 1072 KB Output is correct
17 Correct 41 ms 5692 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 289 ms 18036 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 382 ms 17448 KB Output is correct
31 Correct 402 ms 19108 KB Output is correct
32 Correct 368 ms 19108 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 373 ms 19036 KB Output is correct
35 Correct 371 ms 19028 KB Output is correct
36 Correct 388 ms 19092 KB Output is correct
37 Correct 442 ms 53116 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 39 ms 5692 KB Output is correct
40 Correct 53 ms 5692 KB Output is correct
41 Correct 43 ms 5628 KB Output is correct
42 Correct 38 ms 5696 KB Output is correct
43 Correct 38 ms 5700 KB Output is correct
44 Correct 42 ms 5716 KB Output is correct
45 Correct 37 ms 5700 KB Output is correct
46 Correct 43 ms 5688 KB Output is correct
47 Correct 39 ms 5688 KB Output is correct
48 Correct 41 ms 5636 KB Output is correct
49 Correct 42 ms 5700 KB Output is correct
50 Correct 40 ms 5628 KB Output is correct
51 Correct 396 ms 19120 KB Output is correct
52 Correct 403 ms 18980 KB Output is correct
53 Correct 421 ms 19108 KB Output is correct
54 Correct 56 ms 5692 KB Output is correct
55 Correct 45 ms 5628 KB Output is correct
56 Correct 118 ms 18456 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
58 Correct 45 ms 5564 KB Output is correct
59 Correct 43 ms 5672 KB Output is correct
60 Correct 497 ms 18936 KB Output is correct
61 Correct 40 ms 5692 KB Output is correct
62 Correct 40 ms 5632 KB Output is correct
63 Correct 44 ms 5708 KB Output is correct
64 Correct 46 ms 5696 KB Output is correct
65 Correct 44 ms 5608 KB Output is correct
66 Correct 48 ms 5688 KB Output is correct
67 Correct 40 ms 5692 KB Output is correct
68 Correct 35 ms 5696 KB Output is correct
69 Correct 43 ms 5620 KB Output is correct
70 Correct 417 ms 18856 KB Output is correct
71 Correct 41 ms 5688 KB Output is correct
72 Correct 442 ms 53180 KB Output is correct
73 Correct 446 ms 53148 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 0 ms 204 KB Output is correct
76 Correct 0 ms 204 KB Output is correct
77 Correct 0 ms 204 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 4 ms 976 KB Output is correct
80 Correct 481 ms 53124 KB Output is correct
81 Correct 470 ms 53080 KB Output is correct
82 Correct 426 ms 53136 KB Output is correct
83 Correct 426 ms 53256 KB Output is correct
84 Correct 508 ms 53212 KB Output is correct
85 Correct 434 ms 53208 KB Output is correct
86 Correct 150 ms 18440 KB Output is correct
87 Correct 0 ms 204 KB Output is correct