# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
348119 | 2021-01-14T09:43:31 Z | arnold518 | Strange Device (APIO19_strange_device) | C++14 | 867 ms | 82936 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; int N; ll A, B, L; pll P[MAXN+10]; map<ll, ll> M; void addrange(ll l, ll r) { M[l]++; M[r+1]--; } int main() { scanf("%d%lld%lld", &N, &A, &B); for(int i=1; i<=N; i++) scanf("%lld%lld", &P[i].first, &P[i].second); L=__gcd(A, B+1); if(A/L>=(ll)1e18/B) L=1e18; else L=A/L*B; for(int i=1; i<=N; i++) { ll l=P[i].first, r=P[i].second; if(r-l+1>=L) return !printf("%lld\n", L); if(l%L<=r%L) addrange(l%L, r%L); else { addrange(l%L, L-1); addrange(0, r%L); } } M[L]; ll t=0, ans=0; for(auto it=M.begin(); it!=M.end(); it++) { if(it->first==L) break; t+=it->second; if(t) ans+=next(it)->first-it->first; } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 7 ms | 1516 KB | Output is correct |
3 | Correct | 7 ms | 1516 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 0 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 | 640 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 | 7 ms | 1516 KB | Output is correct |
17 | Correct | 81 ms | 12108 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 | 0 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 | 1 ms | 492 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 356 ms | 16364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 787 ms | 82936 KB | Output is correct |
3 | Correct | 790 ms | 79544 KB | Output is correct |
4 | Correct | 851 ms | 79600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 787 ms | 82936 KB | Output is correct |
3 | Correct | 790 ms | 79544 KB | Output is correct |
4 | Correct | 851 ms | 79600 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 784 ms | 79340 KB | Output is correct |
7 | Correct | 794 ms | 79440 KB | Output is correct |
8 | Correct | 821 ms | 79340 KB | Output is correct |
9 | Correct | 842 ms | 79340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 787 ms | 82936 KB | Output is correct |
3 | Correct | 790 ms | 79544 KB | Output is correct |
4 | Correct | 851 ms | 79600 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 91 ms | 12012 KB | Output is correct |
7 | Correct | 74 ms | 11884 KB | Output is correct |
8 | Correct | 71 ms | 11884 KB | Output is correct |
9 | Correct | 76 ms | 11884 KB | Output is correct |
10 | Correct | 70 ms | 11948 KB | Output is correct |
11 | Correct | 69 ms | 11884 KB | Output is correct |
12 | Correct | 76 ms | 11884 KB | Output is correct |
13 | Correct | 77 ms | 11884 KB | Output is correct |
14 | Correct | 71 ms | 11884 KB | Output is correct |
15 | Correct | 85 ms | 11884 KB | Output is correct |
16 | Correct | 81 ms | 11884 KB | Output is correct |
17 | Correct | 79 ms | 11892 KB | Output is correct |
18 | Correct | 776 ms | 79632 KB | Output is correct |
19 | Correct | 807 ms | 79604 KB | Output is correct |
20 | Correct | 841 ms | 79596 KB | Output is correct |
21 | Correct | 72 ms | 12012 KB | Output is correct |
22 | Correct | 75 ms | 11884 KB | Output is correct |
23 | Correct | 143 ms | 18284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Correct | 79 ms | 11884 KB | Output is correct |
3 | Correct | 78 ms | 11884 KB | Output is correct |
4 | Correct | 822 ms | 79468 KB | Output is correct |
5 | Correct | 78 ms | 11884 KB | Output is correct |
6 | Correct | 79 ms | 12012 KB | Output is correct |
7 | Correct | 79 ms | 12012 KB | Output is correct |
8 | Correct | 81 ms | 11884 KB | Output is correct |
9 | Correct | 80 ms | 11884 KB | Output is correct |
10 | Correct | 75 ms | 11884 KB | Output is correct |
11 | Correct | 74 ms | 11884 KB | Output is correct |
12 | Correct | 78 ms | 11884 KB | Output is correct |
13 | Correct | 79 ms | 11884 KB | Output is correct |
14 | Correct | 841 ms | 79668 KB | Output is correct |
15 | Correct | 71 ms | 11884 KB | Output is correct |
16 | Correct | 766 ms | 79724 KB | Output is correct |
17 | Correct | 772 ms | 79636 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 | 1516 KB | Output is correct |
3 | Correct | 7 ms | 1516 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 0 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 | 640 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 | 7 ms | 1516 KB | Output is correct |
17 | Correct | 81 ms | 12108 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 | 0 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 | 1 ms | 492 KB | Output is correct |
27 | Correct | 2 ms | 492 KB | Output is correct |
28 | Correct | 356 ms | 16364 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 787 ms | 82936 KB | Output is correct |
31 | Correct | 790 ms | 79544 KB | Output is correct |
32 | Correct | 851 ms | 79600 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 784 ms | 79340 KB | Output is correct |
35 | Correct | 794 ms | 79440 KB | Output is correct |
36 | Correct | 821 ms | 79340 KB | Output is correct |
37 | Correct | 842 ms | 79340 KB | Output is correct |
38 | Correct | 2 ms | 364 KB | Output is correct |
39 | Correct | 91 ms | 12012 KB | Output is correct |
40 | Correct | 74 ms | 11884 KB | Output is correct |
41 | Correct | 71 ms | 11884 KB | Output is correct |
42 | Correct | 76 ms | 11884 KB | Output is correct |
43 | Correct | 70 ms | 11948 KB | Output is correct |
44 | Correct | 69 ms | 11884 KB | Output is correct |
45 | Correct | 76 ms | 11884 KB | Output is correct |
46 | Correct | 77 ms | 11884 KB | Output is correct |
47 | Correct | 71 ms | 11884 KB | Output is correct |
48 | Correct | 85 ms | 11884 KB | Output is correct |
49 | Correct | 81 ms | 11884 KB | Output is correct |
50 | Correct | 79 ms | 11892 KB | Output is correct |
51 | Correct | 776 ms | 79632 KB | Output is correct |
52 | Correct | 807 ms | 79604 KB | Output is correct |
53 | Correct | 841 ms | 79596 KB | Output is correct |
54 | Correct | 72 ms | 12012 KB | Output is correct |
55 | Correct | 75 ms | 11884 KB | Output is correct |
56 | Correct | 143 ms | 18284 KB | Output is correct |
57 | Correct | 0 ms | 364 KB | Output is correct |
58 | Correct | 79 ms | 11884 KB | Output is correct |
59 | Correct | 78 ms | 11884 KB | Output is correct |
60 | Correct | 822 ms | 79468 KB | Output is correct |
61 | Correct | 78 ms | 11884 KB | Output is correct |
62 | Correct | 79 ms | 12012 KB | Output is correct |
63 | Correct | 79 ms | 12012 KB | Output is correct |
64 | Correct | 81 ms | 11884 KB | Output is correct |
65 | Correct | 80 ms | 11884 KB | Output is correct |
66 | Correct | 75 ms | 11884 KB | Output is correct |
67 | Correct | 74 ms | 11884 KB | Output is correct |
68 | Correct | 78 ms | 11884 KB | Output is correct |
69 | Correct | 79 ms | 11884 KB | Output is correct |
70 | Correct | 841 ms | 79668 KB | Output is correct |
71 | Correct | 71 ms | 11884 KB | Output is correct |
72 | Correct | 766 ms | 79724 KB | Output is correct |
73 | Correct | 772 ms | 79636 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 | 8 ms | 1536 KB | Output is correct |
80 | Correct | 827 ms | 79852 KB | Output is correct |
81 | Correct | 827 ms | 79576 KB | Output is correct |
82 | Correct | 832 ms | 79724 KB | Output is correct |
83 | Correct | 867 ms | 79596 KB | Output is correct |
84 | Correct | 853 ms | 79596 KB | Output is correct |
85 | Correct | 810 ms | 79724 KB | Output is correct |
86 | Correct | 143 ms | 18156 KB | Output is correct |
87 | Correct | 1 ms | 364 KB | Output is correct |