Submission #516269

# Submission time Handle Problem Language Result Execution time Memory
516269 2022-01-21T00:43:28 Z jk410 Strange Device (APIO19_strange_device) C++17
100 / 100
685 ms 86232 KB
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
struct gugan{
    ll l,r;
};
struct q{
    ll t;
    int v;
    bool operator<(const q &tmp)const{
        return t<tmp.t;
    }
};
int N;
ll A,B,T,Ans;
gugan G[1000001];
vector<q> V;
void f(ll l,ll r){
    V.push_back({l,1});
    V.push_back({r+1,-1});
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>A>>B;
    if (log10(A/__gcd(A,B+1))+log10(B)>18)
        T=1e18+1;
    else
        T=A/__gcd(A,B+1)*B;
    for (int i=1; i<=N; i++){
        cin>>G[i].l>>G[i].r;
        if (G[i].r-G[i].l+1>=T){
            cout<<T;
            return 0;
        }
    }
    for (int i=1; i<=N; i++){
        G[i].l%=T;
        G[i].r%=T;
        if (G[i].l>G[i].r){
            f(0,G[i].r);
            f(G[i].l,T-1);
        }
        else
            f(G[i].l,G[i].r);
    }
    sort(all(V));
    for (int i=0,j,v=0,tmp; i<(int)V.size();){
        if (!v)
            tmp=i;
        for (j=i; j<(int)V.size()&&V[j].t==V[i].t; j++)
            v+=V[j].v;
        if (!v)
            Ans+=V[i].t-V[tmp].t;
        i=j;
    }
    cout<<Ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 6 ms 1480 KB Output is correct
3 Correct 5 ms 1488 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 6 ms 1464 KB Output is correct
17 Correct 58 ms 9816 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 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 352 ms 74032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 511 ms 61100 KB Output is correct
3 Correct 601 ms 61028 KB Output is correct
4 Correct 509 ms 85988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 511 ms 61100 KB Output is correct
3 Correct 601 ms 61028 KB Output is correct
4 Correct 509 ms 85988 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 540 ms 86068 KB Output is correct
7 Correct 521 ms 85996 KB Output is correct
8 Correct 538 ms 86008 KB Output is correct
9 Correct 631 ms 85988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 511 ms 61100 KB Output is correct
3 Correct 601 ms 61028 KB Output is correct
4 Correct 509 ms 85988 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 48 ms 9824 KB Output is correct
7 Correct 56 ms 9824 KB Output is correct
8 Correct 45 ms 9808 KB Output is correct
9 Correct 54 ms 9884 KB Output is correct
10 Correct 47 ms 9784 KB Output is correct
11 Correct 52 ms 9764 KB Output is correct
12 Correct 47 ms 9816 KB Output is correct
13 Correct 59 ms 9772 KB Output is correct
14 Correct 52 ms 9792 KB Output is correct
15 Correct 56 ms 9788 KB Output is correct
16 Correct 55 ms 9784 KB Output is correct
17 Correct 47 ms 9784 KB Output is correct
18 Correct 516 ms 85956 KB Output is correct
19 Correct 495 ms 86052 KB Output is correct
20 Correct 653 ms 86116 KB Output is correct
21 Correct 61 ms 9800 KB Output is correct
22 Correct 43 ms 9856 KB Output is correct
23 Correct 136 ms 34744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 58 ms 9776 KB Output is correct
3 Correct 61 ms 9852 KB Output is correct
4 Correct 685 ms 86036 KB Output is correct
5 Correct 54 ms 9804 KB Output is correct
6 Correct 54 ms 9724 KB Output is correct
7 Correct 56 ms 9788 KB Output is correct
8 Correct 57 ms 9744 KB Output is correct
9 Correct 54 ms 9776 KB Output is correct
10 Correct 58 ms 9736 KB Output is correct
11 Correct 60 ms 9868 KB Output is correct
12 Correct 50 ms 9804 KB Output is correct
13 Correct 56 ms 9788 KB Output is correct
14 Correct 627 ms 86032 KB Output is correct
15 Correct 66 ms 9868 KB Output is correct
16 Correct 490 ms 86232 KB Output is correct
17 Correct 511 ms 86024 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 6 ms 1480 KB Output is correct
3 Correct 5 ms 1488 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 6 ms 1464 KB Output is correct
17 Correct 58 ms 9816 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 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 320 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 352 ms 74032 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 511 ms 61100 KB Output is correct
31 Correct 601 ms 61028 KB Output is correct
32 Correct 509 ms 85988 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 540 ms 86068 KB Output is correct
35 Correct 521 ms 85996 KB Output is correct
36 Correct 538 ms 86008 KB Output is correct
37 Correct 631 ms 85988 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 48 ms 9824 KB Output is correct
40 Correct 56 ms 9824 KB Output is correct
41 Correct 45 ms 9808 KB Output is correct
42 Correct 54 ms 9884 KB Output is correct
43 Correct 47 ms 9784 KB Output is correct
44 Correct 52 ms 9764 KB Output is correct
45 Correct 47 ms 9816 KB Output is correct
46 Correct 59 ms 9772 KB Output is correct
47 Correct 52 ms 9792 KB Output is correct
48 Correct 56 ms 9788 KB Output is correct
49 Correct 55 ms 9784 KB Output is correct
50 Correct 47 ms 9784 KB Output is correct
51 Correct 516 ms 85956 KB Output is correct
52 Correct 495 ms 86052 KB Output is correct
53 Correct 653 ms 86116 KB Output is correct
54 Correct 61 ms 9800 KB Output is correct
55 Correct 43 ms 9856 KB Output is correct
56 Correct 136 ms 34744 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
58 Correct 58 ms 9776 KB Output is correct
59 Correct 61 ms 9852 KB Output is correct
60 Correct 685 ms 86036 KB Output is correct
61 Correct 54 ms 9804 KB Output is correct
62 Correct 54 ms 9724 KB Output is correct
63 Correct 56 ms 9788 KB Output is correct
64 Correct 57 ms 9744 KB Output is correct
65 Correct 54 ms 9776 KB Output is correct
66 Correct 58 ms 9736 KB Output is correct
67 Correct 60 ms 9868 KB Output is correct
68 Correct 50 ms 9804 KB Output is correct
69 Correct 56 ms 9788 KB Output is correct
70 Correct 627 ms 86032 KB Output is correct
71 Correct 66 ms 9868 KB Output is correct
72 Correct 490 ms 86232 KB Output is correct
73 Correct 511 ms 86024 KB Output is correct
74 Correct 0 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 1 ms 316 KB Output is correct
79 Correct 5 ms 1380 KB Output is correct
80 Correct 685 ms 86012 KB Output is correct
81 Correct 678 ms 86084 KB Output is correct
82 Correct 632 ms 86020 KB Output is correct
83 Correct 657 ms 85972 KB Output is correct
84 Correct 647 ms 85948 KB Output is correct
85 Correct 622 ms 85948 KB Output is correct
86 Correct 135 ms 34768 KB Output is correct
87 Correct 0 ms 204 KB Output is correct