Submission #252085

# Submission time Handle Problem Language Result Execution time Memory
252085 2020-07-24T06:10:44 Z jeqcho Strange Device (APIO19_strange_device) C++17
100 / 100
1146 ms 148336 KB
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
#define ll long long
#define MAX 1000100
inline ll read()
{
    ll x=0;bool t=false;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=true,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}
ll n,sum,l[MAX],r[MAX],A,B,d,T,ans;
multiset<pair<ll,int> >S;
#define mp make_pair
void Add(ll l,ll r){S.insert(mp(l,1));S.insert(mp(r+1,-1));}
int main()
{
    n=read();A=read();B=read();d=__gcd(A,B+1);
    for(int i=1;i<=n;++i)l[i]=read(),r[i]=read(),sum+=r[i]-l[i]+1;
    if(1.0*A*B/d>1e18){printf("%lld\n",sum);return 0;}
    T=A/d*B;
    for(int i=1;i<=n;++i)
    {
        if(r[i]-l[i]+1>=T){printf("%lld\n",T);return 0;}
        if(l[i]/T!=r[i]/T)Add(l[i]%T,T-1),Add(0,r[i]%T);
        else Add(l[i]%T,r[i]%T);
    }
    S.insert(mp(T,0));
    ll lst=-1,c=0;
    for(auto a:S)
    {
        if(c>0)ans+=a.first-lst;
        c+=a.second;
        lst=a.first;
    }
    printf("%lld\n",ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 9 ms 1792 KB Output is correct
3 Correct 9 ms 1792 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 8 ms 1792 KB Output is correct
17 Correct 99 ms 14468 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1061 ms 141268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1020 ms 141228 KB Output is correct
3 Correct 1060 ms 141304 KB Output is correct
4 Correct 1052 ms 141260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1020 ms 141228 KB Output is correct
3 Correct 1060 ms 141304 KB Output is correct
4 Correct 1052 ms 141260 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1064 ms 141300 KB Output is correct
7 Correct 1049 ms 141492 KB Output is correct
8 Correct 1016 ms 141296 KB Output is correct
9 Correct 1092 ms 141160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1020 ms 141228 KB Output is correct
3 Correct 1060 ms 141304 KB Output is correct
4 Correct 1052 ms 141260 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 86 ms 14456 KB Output is correct
7 Correct 90 ms 14456 KB Output is correct
8 Correct 92 ms 14460 KB Output is correct
9 Correct 99 ms 14456 KB Output is correct
10 Correct 87 ms 14460 KB Output is correct
11 Correct 100 ms 14456 KB Output is correct
12 Correct 98 ms 14456 KB Output is correct
13 Correct 101 ms 14476 KB Output is correct
14 Correct 88 ms 14456 KB Output is correct
15 Correct 110 ms 14456 KB Output is correct
16 Correct 105 ms 14456 KB Output is correct
17 Correct 97 ms 14456 KB Output is correct
18 Correct 1042 ms 141208 KB Output is correct
19 Correct 1100 ms 141176 KB Output is correct
20 Correct 1106 ms 141148 KB Output is correct
21 Correct 97 ms 14456 KB Output is correct
22 Correct 94 ms 14456 KB Output is correct
23 Correct 395 ms 48376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 104 ms 14456 KB Output is correct
3 Correct 109 ms 14456 KB Output is correct
4 Correct 1063 ms 141944 KB Output is correct
5 Correct 108 ms 14456 KB Output is correct
6 Correct 117 ms 14456 KB Output is correct
7 Correct 106 ms 14456 KB Output is correct
8 Correct 102 ms 14460 KB Output is correct
9 Correct 100 ms 14584 KB Output is correct
10 Correct 100 ms 14456 KB Output is correct
11 Correct 98 ms 14456 KB Output is correct
12 Correct 100 ms 14380 KB Output is correct
13 Correct 117 ms 14456 KB Output is correct
14 Correct 1140 ms 141672 KB Output is correct
15 Correct 95 ms 14456 KB Output is correct
16 Correct 1022 ms 141316 KB Output is correct
17 Correct 1012 ms 141272 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 9 ms 1792 KB Output is correct
3 Correct 9 ms 1792 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 8 ms 1792 KB Output is correct
17 Correct 99 ms 14468 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1061 ms 141268 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1020 ms 141228 KB Output is correct
31 Correct 1060 ms 141304 KB Output is correct
32 Correct 1052 ms 141260 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1064 ms 141300 KB Output is correct
35 Correct 1049 ms 141492 KB Output is correct
36 Correct 1016 ms 141296 KB Output is correct
37 Correct 1092 ms 141160 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 86 ms 14456 KB Output is correct
40 Correct 90 ms 14456 KB Output is correct
41 Correct 92 ms 14460 KB Output is correct
42 Correct 99 ms 14456 KB Output is correct
43 Correct 87 ms 14460 KB Output is correct
44 Correct 100 ms 14456 KB Output is correct
45 Correct 98 ms 14456 KB Output is correct
46 Correct 101 ms 14476 KB Output is correct
47 Correct 88 ms 14456 KB Output is correct
48 Correct 110 ms 14456 KB Output is correct
49 Correct 105 ms 14456 KB Output is correct
50 Correct 97 ms 14456 KB Output is correct
51 Correct 1042 ms 141208 KB Output is correct
52 Correct 1100 ms 141176 KB Output is correct
53 Correct 1106 ms 141148 KB Output is correct
54 Correct 97 ms 14456 KB Output is correct
55 Correct 94 ms 14456 KB Output is correct
56 Correct 395 ms 48376 KB Output is correct
57 Correct 0 ms 384 KB Output is correct
58 Correct 104 ms 14456 KB Output is correct
59 Correct 109 ms 14456 KB Output is correct
60 Correct 1063 ms 141944 KB Output is correct
61 Correct 108 ms 14456 KB Output is correct
62 Correct 117 ms 14456 KB Output is correct
63 Correct 106 ms 14456 KB Output is correct
64 Correct 102 ms 14460 KB Output is correct
65 Correct 100 ms 14584 KB Output is correct
66 Correct 100 ms 14456 KB Output is correct
67 Correct 98 ms 14456 KB Output is correct
68 Correct 100 ms 14380 KB Output is correct
69 Correct 117 ms 14456 KB Output is correct
70 Correct 1140 ms 141672 KB Output is correct
71 Correct 95 ms 14456 KB Output is correct
72 Correct 1022 ms 141316 KB Output is correct
73 Correct 1012 ms 141272 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 0 ms 256 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 10 ms 2048 KB Output is correct
80 Correct 1082 ms 148164 KB Output is correct
81 Correct 1107 ms 148276 KB Output is correct
82 Correct 1085 ms 148336 KB Output is correct
83 Correct 1146 ms 148288 KB Output is correct
84 Correct 1137 ms 148216 KB Output is correct
85 Correct 1052 ms 148300 KB Output is correct
86 Correct 391 ms 55284 KB Output is correct
87 Correct 1 ms 384 KB Output is correct