Submission #338085

# Submission time Handle Problem Language Result Execution time Memory
338085 2020-12-22T12:57:54 Z Sho10 Strange Device (APIO19_strange_device) C++14
100 / 100
1030 ms 100588 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a,b;
map<ll,ll>m;
int32_t main(){
CODE_START;
cin>>n>>a>>b;
ll ans=0;
ll MOD = log10(a) - log10(__gcd(a, b+1)) + log10(b) > 18 ? (long long)(1e18+1) : a / __gcd(a, b+1) * b;
while(n--){
    ll l,r;
    cin>>l>>r;
   ll L=l%MOD,R=r%MOD;
		if(r-l>=MOD) ans=MOD;
		else if (L<R) m[L]++,m[R+1]--;
		else if (L>R) m[L]++,m[MOD]--,m[0]++,m[R+1]--;
		else if (l==r) m[L]++,m[L+1]--;
		else ans=MOD;

}
//cout<<MOD<<' '<<ans<<endl;
ll sum=0,s1=1,l;
if(ans!=MOD){
    for(auto it : m){
        sum+=it.s;
       // cout<<it.f<<' '<<it.s<<endl;
        if(sum&&s1){
            l=it.f;
            s1=0;
        }else if(!sum){
        ans+=it.f-l;
        s1=1;
        }
    }
}
cout<<ans<<endl;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:49:18: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |         ans+=it.f-l;
      |              ~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 1388 KB Output is correct
17 Correct 74 ms 10348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 318 ms 25756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 766 ms 63120 KB Output is correct
3 Correct 790 ms 100312 KB Output is correct
4 Correct 823 ms 100460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 766 ms 63120 KB Output is correct
3 Correct 790 ms 100312 KB Output is correct
4 Correct 823 ms 100460 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 785 ms 100188 KB Output is correct
7 Correct 833 ms 100284 KB Output is correct
8 Correct 770 ms 100204 KB Output is correct
9 Correct 901 ms 100332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 766 ms 63120 KB Output is correct
3 Correct 790 ms 100312 KB Output is correct
4 Correct 823 ms 100460 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 66 ms 10348 KB Output is correct
7 Correct 72 ms 10348 KB Output is correct
8 Correct 69 ms 10348 KB Output is correct
9 Correct 77 ms 10348 KB Output is correct
10 Correct 69 ms 10348 KB Output is correct
11 Correct 66 ms 10476 KB Output is correct
12 Correct 72 ms 10368 KB Output is correct
13 Correct 73 ms 10348 KB Output is correct
14 Correct 69 ms 10496 KB Output is correct
15 Correct 77 ms 10348 KB Output is correct
16 Correct 77 ms 10348 KB Output is correct
17 Correct 75 ms 10368 KB Output is correct
18 Correct 783 ms 100204 KB Output is correct
19 Correct 827 ms 100204 KB Output is correct
20 Correct 879 ms 100248 KB Output is correct
21 Correct 69 ms 10348 KB Output is correct
22 Correct 83 ms 10348 KB Output is correct
23 Correct 132 ms 13036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 73 ms 7020 KB Output is correct
3 Correct 77 ms 10348 KB Output is correct
4 Correct 824 ms 100256 KB Output is correct
5 Correct 94 ms 10604 KB Output is correct
6 Correct 78 ms 10348 KB Output is correct
7 Correct 77 ms 10476 KB Output is correct
8 Correct 77 ms 10348 KB Output is correct
9 Correct 75 ms 10376 KB Output is correct
10 Correct 70 ms 10348 KB Output is correct
11 Correct 89 ms 10348 KB Output is correct
12 Correct 99 ms 10348 KB Output is correct
13 Correct 76 ms 10348 KB Output is correct
14 Correct 891 ms 100204 KB Output is correct
15 Correct 82 ms 10372 KB Output is correct
16 Correct 747 ms 100204 KB Output is correct
17 Correct 767 ms 100384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 1388 KB Output is correct
17 Correct 74 ms 10348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 318 ms 25756 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 766 ms 63120 KB Output is correct
31 Correct 790 ms 100312 KB Output is correct
32 Correct 823 ms 100460 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 785 ms 100188 KB Output is correct
35 Correct 833 ms 100284 KB Output is correct
36 Correct 770 ms 100204 KB Output is correct
37 Correct 901 ms 100332 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 66 ms 10348 KB Output is correct
40 Correct 72 ms 10348 KB Output is correct
41 Correct 69 ms 10348 KB Output is correct
42 Correct 77 ms 10348 KB Output is correct
43 Correct 69 ms 10348 KB Output is correct
44 Correct 66 ms 10476 KB Output is correct
45 Correct 72 ms 10368 KB Output is correct
46 Correct 73 ms 10348 KB Output is correct
47 Correct 69 ms 10496 KB Output is correct
48 Correct 77 ms 10348 KB Output is correct
49 Correct 77 ms 10348 KB Output is correct
50 Correct 75 ms 10368 KB Output is correct
51 Correct 783 ms 100204 KB Output is correct
52 Correct 827 ms 100204 KB Output is correct
53 Correct 879 ms 100248 KB Output is correct
54 Correct 69 ms 10348 KB Output is correct
55 Correct 83 ms 10348 KB Output is correct
56 Correct 132 ms 13036 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 73 ms 7020 KB Output is correct
59 Correct 77 ms 10348 KB Output is correct
60 Correct 824 ms 100256 KB Output is correct
61 Correct 94 ms 10604 KB Output is correct
62 Correct 78 ms 10348 KB Output is correct
63 Correct 77 ms 10476 KB Output is correct
64 Correct 77 ms 10348 KB Output is correct
65 Correct 75 ms 10376 KB Output is correct
66 Correct 70 ms 10348 KB Output is correct
67 Correct 89 ms 10348 KB Output is correct
68 Correct 99 ms 10348 KB Output is correct
69 Correct 76 ms 10348 KB Output is correct
70 Correct 891 ms 100204 KB Output is correct
71 Correct 82 ms 10372 KB Output is correct
72 Correct 747 ms 100204 KB Output is correct
73 Correct 767 ms 100384 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 7 ms 1388 KB Output is correct
80 Correct 907 ms 100188 KB Output is correct
81 Correct 871 ms 100588 KB Output is correct
82 Correct 936 ms 100460 KB Output is correct
83 Correct 959 ms 100144 KB Output is correct
84 Correct 1030 ms 100560 KB Output is correct
85 Correct 931 ms 100204 KB Output is correct
86 Correct 129 ms 12908 KB Output is correct
87 Correct 1 ms 364 KB Output is correct