Submission #732845

# Submission time Handle Problem Language Result Execution time Memory
732845 2023-04-29T10:43:15 Z Magikarp4000 Strange Device (APIO19_strange_device) C++17
100 / 100
506 ms 35208 KB
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 2e18;

ll n,a,b;
vector<PLL> v;

__int128_t gcd(__int128_t a, __int128_t b) {
    return (b == 0) ? a : gcd(b,a%b);
}

int main() {
    OPTM;
    cin >> n >> a >> b;
    __int128_t p = __int128_t(a)*__int128_t(b)/gcd(__int128_t(a),__int128_t(b)+1);
    FOR(i,0,n) {
        ll l,r; cin >> l >> r;
        ll c = l%p, d = r%p;
        if (r-l+1 >= p) v.PB({0,p-1});
        else if (d >= c) v.PB({c,d});
        else {
            v.PB({c,p-1});
            v.PB({0ll,d});
        }
    }
    ll res = 0;
    sort(ALL(v));
    ll vn = v.size();
    ll s = v[0].F, e = v[0].S;
    FOR(i,1,vn) {
        if (v[i].F <= e) e = max(e,v[i].S);
        else {
            res += e-s+1;
            s = v[i].F;
            e = v[i].S;
        }
    }
    res += e-s+1;
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 220 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 600 KB Output is correct
17 Correct 44 ms 2444 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 289 ms 16900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 391 ms 16788 KB Output is correct
3 Correct 375 ms 16816 KB Output is correct
4 Correct 383 ms 16800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 391 ms 16788 KB Output is correct
3 Correct 375 ms 16816 KB Output is correct
4 Correct 383 ms 16800 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 408 ms 16796 KB Output is correct
7 Correct 391 ms 16824 KB Output is correct
8 Correct 407 ms 16796 KB Output is correct
9 Correct 434 ms 16820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 391 ms 16788 KB Output is correct
3 Correct 375 ms 16816 KB Output is correct
4 Correct 383 ms 16800 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 42 ms 2480 KB Output is correct
7 Correct 41 ms 2508 KB Output is correct
8 Correct 38 ms 2512 KB Output is correct
9 Correct 39 ms 2512 KB Output is correct
10 Correct 41 ms 2484 KB Output is correct
11 Correct 45 ms 2456 KB Output is correct
12 Correct 38 ms 2512 KB Output is correct
13 Correct 41 ms 2404 KB Output is correct
14 Correct 37 ms 2504 KB Output is correct
15 Correct 43 ms 2464 KB Output is correct
16 Correct 45 ms 2512 KB Output is correct
17 Correct 42 ms 2464 KB Output is correct
18 Correct 414 ms 16800 KB Output is correct
19 Correct 416 ms 16780 KB Output is correct
20 Correct 459 ms 16824 KB Output is correct
21 Correct 45 ms 2412 KB Output is correct
22 Correct 39 ms 2512 KB Output is correct
23 Correct 120 ms 8720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 44 ms 2396 KB Output is correct
3 Correct 43 ms 2484 KB Output is correct
4 Correct 455 ms 16920 KB Output is correct
5 Correct 40 ms 2524 KB Output is correct
6 Correct 43 ms 2392 KB Output is correct
7 Correct 44 ms 2416 KB Output is correct
8 Correct 44 ms 2420 KB Output is correct
9 Correct 41 ms 2496 KB Output is correct
10 Correct 40 ms 2428 KB Output is correct
11 Correct 43 ms 2512 KB Output is correct
12 Correct 38 ms 2428 KB Output is correct
13 Correct 43 ms 2400 KB Output is correct
14 Correct 423 ms 16956 KB Output is correct
15 Correct 44 ms 2512 KB Output is correct
16 Correct 412 ms 16760 KB Output is correct
17 Correct 368 ms 16792 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 220 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 600 KB Output is correct
17 Correct 44 ms 2444 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 289 ms 16900 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 391 ms 16788 KB Output is correct
31 Correct 375 ms 16816 KB Output is correct
32 Correct 383 ms 16800 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 408 ms 16796 KB Output is correct
35 Correct 391 ms 16824 KB Output is correct
36 Correct 407 ms 16796 KB Output is correct
37 Correct 434 ms 16820 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 42 ms 2480 KB Output is correct
40 Correct 41 ms 2508 KB Output is correct
41 Correct 38 ms 2512 KB Output is correct
42 Correct 39 ms 2512 KB Output is correct
43 Correct 41 ms 2484 KB Output is correct
44 Correct 45 ms 2456 KB Output is correct
45 Correct 38 ms 2512 KB Output is correct
46 Correct 41 ms 2404 KB Output is correct
47 Correct 37 ms 2504 KB Output is correct
48 Correct 43 ms 2464 KB Output is correct
49 Correct 45 ms 2512 KB Output is correct
50 Correct 42 ms 2464 KB Output is correct
51 Correct 414 ms 16800 KB Output is correct
52 Correct 416 ms 16780 KB Output is correct
53 Correct 459 ms 16824 KB Output is correct
54 Correct 45 ms 2412 KB Output is correct
55 Correct 39 ms 2512 KB Output is correct
56 Correct 120 ms 8720 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 44 ms 2396 KB Output is correct
59 Correct 43 ms 2484 KB Output is correct
60 Correct 455 ms 16920 KB Output is correct
61 Correct 40 ms 2524 KB Output is correct
62 Correct 43 ms 2392 KB Output is correct
63 Correct 44 ms 2416 KB Output is correct
64 Correct 44 ms 2420 KB Output is correct
65 Correct 41 ms 2496 KB Output is correct
66 Correct 40 ms 2428 KB Output is correct
67 Correct 43 ms 2512 KB Output is correct
68 Correct 38 ms 2428 KB Output is correct
69 Correct 43 ms 2400 KB Output is correct
70 Correct 423 ms 16956 KB Output is correct
71 Correct 44 ms 2512 KB Output is correct
72 Correct 412 ms 16760 KB Output is correct
73 Correct 368 ms 16792 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 320 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 5 ms 992 KB Output is correct
80 Correct 469 ms 34996 KB Output is correct
81 Correct 506 ms 35208 KB Output is correct
82 Correct 464 ms 35192 KB Output is correct
83 Correct 445 ms 35008 KB Output is correct
84 Correct 470 ms 35040 KB Output is correct
85 Correct 492 ms 35068 KB Output is correct
86 Correct 144 ms 18432 KB Output is correct
87 Correct 1 ms 316 KB Output is correct