Submission #983242

# Submission time Handle Problem Language Result Execution time Memory
983242 2024-05-15T09:43:11 Z Abito Strange Device (APIO19_strange_device) C++17
100 / 100
477 ms 168504 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=1e6+5;
int n,l[N],r[N],a,b;
__int128 A,B,L[N],R[N];
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>a>>b;
    a/=__gcd(a,b+1);
    A=a,B=b;
    A*=B;
    for (int i=1;i<=n;i++){
        cin>>l[i]>>r[i];
        L[i]=l[i];
        R[i]=r[i];
    }
    vector<pair<__int128,__int128>> v;
    for (int i=1;i<=n;i++){
        if (R[i]-L[i]+1>=A) v.pb({0,A-1});
        else{
            if (R[i]%A>=L[i]%A) v.pb({L[i]%A,R[i]%A});
            else{
                v.pb({L[i]%A,A-1});
                v.pb({0,R[i]%A});
            }
        }
    }
    sort(v.begin(),v.end());
    //for (auto u:v) cout<<u.F<<' '<<u.S<<endl;
    pair<__int128,__int128> cur=v[0];
    vector<pair<__int128,__int128>> f;
    for (auto u:v){
        __int128 ll=max(cur.F,u.F),rr=min(cur.S,u.S);
        if (ll>rr){
            f.pb(cur);
            cur=u;
        }
        else{
            ll=min(cur.F,u.F);
            rr=max(cur.S,u.S);
            cur={ll,rr};
        }
    }
    f.pb(cur);
    int ans=0;
    for (auto u:f){
        __int128 len=u.S-u.F+1;
        ans+=(int)len;
    }cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 6 ms 10204 KB Output is correct
3 Correct 6 ms 10288 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6504 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 5 ms 10204 KB Output is correct
17 Correct 42 ms 26744 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 2 ms 6616 KB Output is correct
3 Correct 2 ms 6612 KB Output is correct
4 Correct 2 ms 6624 KB Output is correct
5 Correct 326 ms 106668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6600 KB Output is correct
2 Correct 434 ms 167276 KB Output is correct
3 Correct 455 ms 165244 KB Output is correct
4 Correct 389 ms 167284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6600 KB Output is correct
2 Correct 434 ms 167276 KB Output is correct
3 Correct 455 ms 165244 KB Output is correct
4 Correct 389 ms 167284 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 364 ms 166396 KB Output is correct
7 Correct 354 ms 167412 KB Output is correct
8 Correct 368 ms 165400 KB Output is correct
9 Correct 400 ms 165272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6600 KB Output is correct
2 Correct 434 ms 167276 KB Output is correct
3 Correct 455 ms 165244 KB Output is correct
4 Correct 389 ms 167284 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 36 ms 26052 KB Output is correct
7 Correct 38 ms 26824 KB Output is correct
8 Correct 36 ms 26568 KB Output is correct
9 Correct 37 ms 26452 KB Output is correct
10 Correct 37 ms 28112 KB Output is correct
11 Correct 38 ms 27956 KB Output is correct
12 Correct 38 ms 26092 KB Output is correct
13 Correct 40 ms 26564 KB Output is correct
14 Correct 35 ms 26728 KB Output is correct
15 Correct 41 ms 26312 KB Output is correct
16 Correct 40 ms 26056 KB Output is correct
17 Correct 44 ms 26308 KB Output is correct
18 Correct 357 ms 165944 KB Output is correct
19 Correct 346 ms 166560 KB Output is correct
20 Correct 428 ms 167044 KB Output is correct
21 Correct 47 ms 26052 KB Output is correct
22 Correct 34 ms 26452 KB Output is correct
23 Correct 102 ms 55744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 39 ms 26312 KB Output is correct
3 Correct 39 ms 26820 KB Output is correct
4 Correct 455 ms 167992 KB Output is correct
5 Correct 44 ms 25948 KB Output is correct
6 Correct 39 ms 26208 KB Output is correct
7 Correct 44 ms 28744 KB Output is correct
8 Correct 40 ms 27500 KB Output is correct
9 Correct 39 ms 27376 KB Output is correct
10 Correct 47 ms 28136 KB Output is correct
11 Correct 47 ms 26612 KB Output is correct
12 Correct 35 ms 26568 KB Output is correct
13 Correct 39 ms 28104 KB Output is correct
14 Correct 412 ms 166748 KB Output is correct
15 Correct 39 ms 26312 KB Output is correct
16 Correct 383 ms 167220 KB Output is correct
17 Correct 386 ms 165648 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 6 ms 10204 KB Output is correct
3 Correct 6 ms 10288 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6504 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 5 ms 10204 KB Output is correct
17 Correct 42 ms 26744 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6616 KB Output is correct
26 Correct 2 ms 6612 KB Output is correct
27 Correct 2 ms 6624 KB Output is correct
28 Correct 326 ms 106668 KB Output is correct
29 Correct 2 ms 6600 KB Output is correct
30 Correct 434 ms 167276 KB Output is correct
31 Correct 455 ms 165244 KB Output is correct
32 Correct 389 ms 167284 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 364 ms 166396 KB Output is correct
35 Correct 354 ms 167412 KB Output is correct
36 Correct 368 ms 165400 KB Output is correct
37 Correct 400 ms 165272 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 36 ms 26052 KB Output is correct
40 Correct 38 ms 26824 KB Output is correct
41 Correct 36 ms 26568 KB Output is correct
42 Correct 37 ms 26452 KB Output is correct
43 Correct 37 ms 28112 KB Output is correct
44 Correct 38 ms 27956 KB Output is correct
45 Correct 38 ms 26092 KB Output is correct
46 Correct 40 ms 26564 KB Output is correct
47 Correct 35 ms 26728 KB Output is correct
48 Correct 41 ms 26312 KB Output is correct
49 Correct 40 ms 26056 KB Output is correct
50 Correct 44 ms 26308 KB Output is correct
51 Correct 357 ms 165944 KB Output is correct
52 Correct 346 ms 166560 KB Output is correct
53 Correct 428 ms 167044 KB Output is correct
54 Correct 47 ms 26052 KB Output is correct
55 Correct 34 ms 26452 KB Output is correct
56 Correct 102 ms 55744 KB Output is correct
57 Correct 1 ms 6488 KB Output is correct
58 Correct 39 ms 26312 KB Output is correct
59 Correct 39 ms 26820 KB Output is correct
60 Correct 455 ms 167992 KB Output is correct
61 Correct 44 ms 25948 KB Output is correct
62 Correct 39 ms 26208 KB Output is correct
63 Correct 44 ms 28744 KB Output is correct
64 Correct 40 ms 27500 KB Output is correct
65 Correct 39 ms 27376 KB Output is correct
66 Correct 47 ms 28136 KB Output is correct
67 Correct 47 ms 26612 KB Output is correct
68 Correct 35 ms 26568 KB Output is correct
69 Correct 39 ms 28104 KB Output is correct
70 Correct 412 ms 166748 KB Output is correct
71 Correct 39 ms 26312 KB Output is correct
72 Correct 383 ms 167220 KB Output is correct
73 Correct 386 ms 165648 KB Output is correct
74 Correct 1 ms 6492 KB Output is correct
75 Correct 1 ms 6492 KB Output is correct
76 Correct 1 ms 6492 KB Output is correct
77 Correct 1 ms 6492 KB Output is correct
78 Correct 1 ms 6492 KB Output is correct
79 Correct 5 ms 10204 KB Output is correct
80 Correct 454 ms 168360 KB Output is correct
81 Correct 477 ms 167412 KB Output is correct
82 Correct 450 ms 165376 KB Output is correct
83 Correct 453 ms 168504 KB Output is correct
84 Correct 411 ms 165700 KB Output is correct
85 Correct 433 ms 166296 KB Output is correct
86 Correct 106 ms 55004 KB Output is correct
87 Correct 1 ms 6624 KB Output is correct