# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
513597 | 2022-01-17T09:55:23 Z | amukkalir | Strange Device (APIO19_strange_device) | C++17 | 978 ms | 53344 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pii pair<int,int> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define mp make_pair ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); } int n; ll a, b; signed main () { scanf("%d %lld %lld", &n, &a, &b); vector<pll> v; for(int i=0; i<n; i++) { ll l, r; scanf("%lld %lld", &l, &r); v.pb(mp(l,r)); } ull ans = 0; //if r max < a*b / gcd(a, b+1) if(v.back().se / b < a / gcd(a, b+1)) { for(int i=0; i<n; i++) { ans += v[i].se - v[i].fi + 1; } } else { ll c = a/gcd(a, b+1) * b; for(int i=0; i<n; i++) { if(v[i].se % c < v[i].fi % c || v[i].se >= v[i].fi + c) { v.pb(mp(0, v[i].se % c)); v[i].se = c-1; } v[i].fi %= c; v[i].se %= c; } cerr << c << endl; sort(v.begin(), v.end(), [&] (pll a, pll b) { if(a.fi % c == b.fi % c) return a.se % c < b.se % c; return a.fi % c < b.fi % c; }); //(auto p : v) cout << p.fi << " " << p.se << endl; for(int i=0; i<v.size(); i++) { int l = i, r = i; ll vl = v[i].fi, vr = v[i].se; while(r + 1 < v.size() && v[r+1].fi <= vr) { vr = max(vr, v[r+1].se); //cout << " :: " << vl << " " << vr << endl; r++; } ans += vr - vl + 1; i = r; } } printf("%llu", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 7 ms | 588 KB | Output is correct |
3 | Correct | 7 ms | 716 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 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 | 0 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 6 ms | 716 KB | Output is correct |
17 | Correct | 91 ms | 2476 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 | 0 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | 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 | 2 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 559 ms | 16760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 718 ms | 16908 KB | Output is correct |
3 | Correct | 677 ms | 16848 KB | Output is correct |
4 | Correct | 815 ms | 53204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 718 ms | 16908 KB | Output is correct |
3 | Correct | 677 ms | 16848 KB | Output is correct |
4 | Correct | 815 ms | 53204 KB | Output is correct |
5 | Correct | 0 ms | 280 KB | Output is correct |
6 | Correct | 739 ms | 53264 KB | Output is correct |
7 | Correct | 735 ms | 53256 KB | Output is correct |
8 | Correct | 711 ms | 53344 KB | Output is correct |
9 | Correct | 925 ms | 53188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 718 ms | 16908 KB | Output is correct |
3 | Correct | 677 ms | 16848 KB | Output is correct |
4 | Correct | 815 ms | 53204 KB | Output is correct |
5 | Correct | 0 ms | 276 KB | Output is correct |
6 | Correct | 76 ms | 5660 KB | Output is correct |
7 | Correct | 77 ms | 5648 KB | Output is correct |
8 | Correct | 60 ms | 5580 KB | Output is correct |
9 | Correct | 71 ms | 5688 KB | Output is correct |
10 | Correct | 71 ms | 5844 KB | Output is correct |
11 | Correct | 75 ms | 5652 KB | Output is correct |
12 | Correct | 66 ms | 5668 KB | Output is correct |
13 | Correct | 87 ms | 5660 KB | Output is correct |
14 | Correct | 67 ms | 5640 KB | Output is correct |
15 | Correct | 85 ms | 5632 KB | Output is correct |
16 | Correct | 85 ms | 5628 KB | Output is correct |
17 | Correct | 71 ms | 5624 KB | Output is correct |
18 | Correct | 728 ms | 53212 KB | Output is correct |
19 | Correct | 708 ms | 53148 KB | Output is correct |
20 | Correct | 942 ms | 53204 KB | Output is correct |
21 | Correct | 82 ms | 5680 KB | Output is correct |
22 | Correct | 61 ms | 5632 KB | Output is correct |
23 | Correct | 214 ms | 18484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 80 ms | 2832 KB | Output is correct |
3 | Correct | 84 ms | 2856 KB | Output is correct |
4 | Correct | 966 ms | 53240 KB | Output is correct |
5 | Correct | 82 ms | 5648 KB | Output is correct |
6 | Correct | 81 ms | 5640 KB | Output is correct |
7 | Correct | 86 ms | 5684 KB | Output is correct |
8 | Correct | 81 ms | 5596 KB | Output is correct |
9 | Correct | 82 ms | 5680 KB | Output is correct |
10 | Correct | 79 ms | 5680 KB | Output is correct |
11 | Correct | 85 ms | 5672 KB | Output is correct |
12 | Correct | 61 ms | 5684 KB | Output is correct |
13 | Correct | 84 ms | 5640 KB | Output is correct |
14 | Correct | 936 ms | 53212 KB | Output is correct |
15 | Correct | 78 ms | 5676 KB | Output is correct |
16 | Correct | 716 ms | 53148 KB | Output is correct |
17 | Correct | 705 ms | 53148 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 | 7 ms | 588 KB | Output is correct |
3 | Correct | 7 ms | 716 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 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 | 0 ms | 204 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 6 ms | 716 KB | Output is correct |
17 | Correct | 91 ms | 2476 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 | 0 ms | 204 KB | Output is correct |
22 | Correct | 1 ms | 204 KB | Output is correct |
23 | Correct | 0 ms | 204 KB | Output is correct |
24 | Correct | 0 ms | 204 KB | Output is correct |
25 | Correct | 2 ms | 204 KB | Output is correct |
26 | Correct | 1 ms | 332 KB | Output is correct |
27 | Correct | 1 ms | 332 KB | Output is correct |
28 | Correct | 559 ms | 16760 KB | Output is correct |
29 | Correct | 0 ms | 204 KB | Output is correct |
30 | Correct | 718 ms | 16908 KB | Output is correct |
31 | Correct | 677 ms | 16848 KB | Output is correct |
32 | Correct | 815 ms | 53204 KB | Output is correct |
33 | Correct | 0 ms | 280 KB | Output is correct |
34 | Correct | 739 ms | 53264 KB | Output is correct |
35 | Correct | 735 ms | 53256 KB | Output is correct |
36 | Correct | 711 ms | 53344 KB | Output is correct |
37 | Correct | 925 ms | 53188 KB | Output is correct |
38 | Correct | 0 ms | 276 KB | Output is correct |
39 | Correct | 76 ms | 5660 KB | Output is correct |
40 | Correct | 77 ms | 5648 KB | Output is correct |
41 | Correct | 60 ms | 5580 KB | Output is correct |
42 | Correct | 71 ms | 5688 KB | Output is correct |
43 | Correct | 71 ms | 5844 KB | Output is correct |
44 | Correct | 75 ms | 5652 KB | Output is correct |
45 | Correct | 66 ms | 5668 KB | Output is correct |
46 | Correct | 87 ms | 5660 KB | Output is correct |
47 | Correct | 67 ms | 5640 KB | Output is correct |
48 | Correct | 85 ms | 5632 KB | Output is correct |
49 | Correct | 85 ms | 5628 KB | Output is correct |
50 | Correct | 71 ms | 5624 KB | Output is correct |
51 | Correct | 728 ms | 53212 KB | Output is correct |
52 | Correct | 708 ms | 53148 KB | Output is correct |
53 | Correct | 942 ms | 53204 KB | Output is correct |
54 | Correct | 82 ms | 5680 KB | Output is correct |
55 | Correct | 61 ms | 5632 KB | Output is correct |
56 | Correct | 214 ms | 18484 KB | Output is correct |
57 | Correct | 1 ms | 204 KB | Output is correct |
58 | Correct | 80 ms | 2832 KB | Output is correct |
59 | Correct | 84 ms | 2856 KB | Output is correct |
60 | Correct | 966 ms | 53240 KB | Output is correct |
61 | Correct | 82 ms | 5648 KB | Output is correct |
62 | Correct | 81 ms | 5640 KB | Output is correct |
63 | Correct | 86 ms | 5684 KB | Output is correct |
64 | Correct | 81 ms | 5596 KB | Output is correct |
65 | Correct | 82 ms | 5680 KB | Output is correct |
66 | Correct | 79 ms | 5680 KB | Output is correct |
67 | Correct | 85 ms | 5672 KB | Output is correct |
68 | Correct | 61 ms | 5684 KB | Output is correct |
69 | Correct | 84 ms | 5640 KB | Output is correct |
70 | Correct | 936 ms | 53212 KB | Output is correct |
71 | Correct | 78 ms | 5676 KB | Output is correct |
72 | Correct | 716 ms | 53148 KB | Output is correct |
73 | Correct | 705 ms | 53148 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 | 292 KB | Output is correct |
78 | Correct | 1 ms | 296 KB | Output is correct |
79 | Correct | 6 ms | 936 KB | Output is correct |
80 | Correct | 973 ms | 53224 KB | Output is correct |
81 | Correct | 978 ms | 53220 KB | Output is correct |
82 | Correct | 950 ms | 53164 KB | Output is correct |
83 | Correct | 936 ms | 52884 KB | Output is correct |
84 | Correct | 951 ms | 52656 KB | Output is correct |
85 | Correct | 948 ms | 52688 KB | Output is correct |
86 | Correct | 214 ms | 18484 KB | Output is correct |
87 | Correct | 1 ms | 204 KB | Output is correct |