Submission #701195

# Submission time Handle Problem Language Result Execution time Memory
701195 2023-02-20T12:31:04 Z whqkrtk04 Strange Device (APIO19_strange_device) C++17
100 / 100
545 ms 69032 KB
#include <bits/stdc++.h>
using namespace std;
typedef __int128_t ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+1;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<int>(x, y)(rng)

ll mod(ll a, ll b) { return ((a%b) + b) % b; }
ll ext_gcd(ll a, ll b, ll &x, ll &y) {
    ll g = a; x = 1, y = 0;
    if(b) g = ext_gcd(b, a % b, y, x), y -= a / b * x;
    return g;
}
ll inv(ll a, ll m) {
    ll x, y; ll g = ext_gcd(a, m, x, y);
    if(g > 1) return -1;
    return mod(x, m);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; long long a, b; cin >> n >> a >> b;
    ll t = (ll)a*b/__gcd(a, b+1);
    vector<pll> A;
    for(int i = 0; i < n; i++) {
        long long x, y; cin >> x >> y; y++;
        if(y-x >= t) {
            A.push_back({0, t});
        } else {
            x %= t, y %= t;
            if(y < x) {
                A.push_back({x, t});
                A.push_back({0, y});
            } else A.push_back({x, y});
        }
    }
    sort(A.begin(), A.end());
    vector<pll> B;
    for(int i = 0; i < A.size(); i++) {
        if(B.empty() || A[i].fi > B.back().se) B.push_back(A[i]);
        else B.back().se = max(B.back().se, A[i].se);
    }
    long long ans = 0LL;
    for(auto i : B) ans += i.se-i.fi;
    cout << ans << "\n";
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<__int128, __int128> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 0; i < A.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 4 ms 856 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 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 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 984 KB Output is correct
17 Correct 44 ms 4564 KB Output is correct
18 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 0 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 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 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 309 ms 33264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 429 ms 33260 KB Output is correct
3 Correct 454 ms 68900 KB Output is correct
4 Correct 471 ms 68848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 429 ms 33260 KB Output is correct
3 Correct 454 ms 68900 KB Output is correct
4 Correct 471 ms 68848 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 444 ms 68920 KB Output is correct
7 Correct 460 ms 68852 KB Output is correct
8 Correct 480 ms 68868 KB Output is correct
9 Correct 545 ms 68884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 429 ms 33260 KB Output is correct
3 Correct 454 ms 68900 KB Output is correct
4 Correct 471 ms 68848 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 43 ms 7212 KB Output is correct
7 Correct 47 ms 7288 KB Output is correct
8 Correct 41 ms 7232 KB Output is correct
9 Correct 43 ms 7264 KB Output is correct
10 Correct 41 ms 7304 KB Output is correct
11 Correct 50 ms 7232 KB Output is correct
12 Correct 41 ms 7212 KB Output is correct
13 Correct 45 ms 7192 KB Output is correct
14 Correct 43 ms 7272 KB Output is correct
15 Correct 53 ms 7188 KB Output is correct
16 Correct 45 ms 7280 KB Output is correct
17 Correct 43 ms 7372 KB Output is correct
18 Correct 480 ms 68948 KB Output is correct
19 Correct 425 ms 68952 KB Output is correct
20 Correct 510 ms 68856 KB Output is correct
21 Correct 44 ms 7196 KB Output is correct
22 Correct 48 ms 7320 KB Output is correct
23 Correct 132 ms 26612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 44 ms 4548 KB Output is correct
3 Correct 42 ms 4548 KB Output is correct
4 Correct 519 ms 33264 KB Output is correct
5 Correct 44 ms 7232 KB Output is correct
6 Correct 58 ms 7272 KB Output is correct
7 Correct 45 ms 7268 KB Output is correct
8 Correct 48 ms 7348 KB Output is correct
9 Correct 53 ms 7228 KB Output is correct
10 Correct 46 ms 7256 KB Output is correct
11 Correct 47 ms 7220 KB Output is correct
12 Correct 39 ms 7296 KB Output is correct
13 Correct 45 ms 7232 KB Output is correct
14 Correct 521 ms 68944 KB Output is correct
15 Correct 55 ms 7264 KB Output is correct
16 Correct 456 ms 69000 KB Output is correct
17 Correct 423 ms 68836 KB Output is correct
18 Correct 1 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 856 KB Output is correct
3 Correct 4 ms 856 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 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 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 984 KB Output is correct
17 Correct 44 ms 4564 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 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 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 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 309 ms 33264 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 429 ms 33260 KB Output is correct
31 Correct 454 ms 68900 KB Output is correct
32 Correct 471 ms 68848 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 444 ms 68920 KB Output is correct
35 Correct 460 ms 68852 KB Output is correct
36 Correct 480 ms 68868 KB Output is correct
37 Correct 545 ms 68884 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 43 ms 7212 KB Output is correct
40 Correct 47 ms 7288 KB Output is correct
41 Correct 41 ms 7232 KB Output is correct
42 Correct 43 ms 7264 KB Output is correct
43 Correct 41 ms 7304 KB Output is correct
44 Correct 50 ms 7232 KB Output is correct
45 Correct 41 ms 7212 KB Output is correct
46 Correct 45 ms 7192 KB Output is correct
47 Correct 43 ms 7272 KB Output is correct
48 Correct 53 ms 7188 KB Output is correct
49 Correct 45 ms 7280 KB Output is correct
50 Correct 43 ms 7372 KB Output is correct
51 Correct 480 ms 68948 KB Output is correct
52 Correct 425 ms 68952 KB Output is correct
53 Correct 510 ms 68856 KB Output is correct
54 Correct 44 ms 7196 KB Output is correct
55 Correct 48 ms 7320 KB Output is correct
56 Correct 132 ms 26612 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 44 ms 4548 KB Output is correct
59 Correct 42 ms 4548 KB Output is correct
60 Correct 519 ms 33264 KB Output is correct
61 Correct 44 ms 7232 KB Output is correct
62 Correct 58 ms 7272 KB Output is correct
63 Correct 45 ms 7268 KB Output is correct
64 Correct 48 ms 7348 KB Output is correct
65 Correct 53 ms 7228 KB Output is correct
66 Correct 46 ms 7256 KB Output is correct
67 Correct 47 ms 7220 KB Output is correct
68 Correct 39 ms 7296 KB Output is correct
69 Correct 45 ms 7232 KB Output is correct
70 Correct 521 ms 68944 KB Output is correct
71 Correct 55 ms 7264 KB Output is correct
72 Correct 456 ms 69000 KB Output is correct
73 Correct 423 ms 68836 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 320 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 324 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 5 ms 1240 KB Output is correct
80 Correct 539 ms 68920 KB Output is correct
81 Correct 531 ms 69032 KB Output is correct
82 Correct 530 ms 68964 KB Output is correct
83 Correct 499 ms 68924 KB Output is correct
84 Correct 535 ms 68868 KB Output is correct
85 Correct 505 ms 68900 KB Output is correct
86 Correct 130 ms 26620 KB Output is correct
87 Correct 1 ms 328 KB Output is correct