Submission #654690

# Submission time Handle Problem Language Result Execution time Memory
654690 2022-11-01T09:13:49 Z horiseun Strange Device (APIO19_strange_device) C++11
100 / 100
645 ms 69000 KB
#include <iostream>
#include <vector>
#include <set>
#include <tuple>
#include <algorithm>
using namespace std;

#define ull unsigned long long
#define f first
#define s second

ull a, b, n, l, r, p, ans, c, lft;
vector<pair<ull, int>> v;

ull gcd(ull x, ull y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> a >> b;
    p = b * (a / gcd(a, b + 1));
    for (int i = 0; i < n; i++) {
        cin >> l >> r;
        if (r - l >= p) {
            cout << p << "\n";
            return 0;
        }
        if ((l + p - 1) % p > (r + p - 1) % p) {
            v.push_back({1, 0});
            v.push_back({(l + p - 1) % p + 1, 0});
            v.push_back({(r + p - 1) % p + 1, 1});
            v.push_back({p, 1});
        } else {
            v.push_back({(l + p - 1) % p + 1, 0});
            v.push_back({(r + p - 1) % p + 1, 1});
        }
    }
    sort(v.begin(), v.end());

    lft = -1;
    for (pair<ull, int> i : v) {
        if (!i.s) {
            c++;
            if (lft == -1) lft = i.f;
        } else {
            c--;
            if (c == 0) {
                ans += (i.f - lft + 1);
                lft = -1;
            }
        }
    }
    cout << ans << "\n";

}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   27 |     for (int i = 0; i < n; i++) {
      |                     ~~^~~
strange_device.cpp:49:21: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   49 |             if (lft == -1) lft = i.f;
      |                 ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 1240 KB Output is correct
3 Correct 5 ms 1240 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1240 KB Output is correct
17 Correct 55 ms 7236 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 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 456 ms 67484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 472 ms 35760 KB Output is correct
3 Correct 504 ms 35088 KB Output is correct
4 Correct 455 ms 35064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 472 ms 35760 KB Output is correct
3 Correct 504 ms 35088 KB Output is correct
4 Correct 455 ms 35064 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 525 ms 35032 KB Output is correct
7 Correct 515 ms 35040 KB Output is correct
8 Correct 536 ms 34936 KB Output is correct
9 Correct 615 ms 34920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 472 ms 35760 KB Output is correct
3 Correct 504 ms 35088 KB Output is correct
4 Correct 455 ms 35064 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 48 ms 7292 KB Output is correct
7 Correct 51 ms 7252 KB Output is correct
8 Correct 50 ms 7228 KB Output is correct
9 Correct 52 ms 7224 KB Output is correct
10 Correct 49 ms 7216 KB Output is correct
11 Correct 48 ms 7216 KB Output is correct
12 Correct 46 ms 7220 KB Output is correct
13 Correct 53 ms 7232 KB Output is correct
14 Correct 47 ms 7172 KB Output is correct
15 Correct 73 ms 7248 KB Output is correct
16 Correct 54 ms 7260 KB Output is correct
17 Correct 49 ms 7268 KB Output is correct
18 Correct 483 ms 34872 KB Output is correct
19 Correct 446 ms 34864 KB Output is correct
20 Correct 575 ms 34924 KB Output is correct
21 Correct 57 ms 7236 KB Output is correct
22 Correct 47 ms 7228 KB Output is correct
23 Correct 196 ms 40616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 53 ms 7272 KB Output is correct
3 Correct 59 ms 7232 KB Output is correct
4 Correct 640 ms 34760 KB Output is correct
5 Correct 55 ms 7248 KB Output is correct
6 Correct 62 ms 7216 KB Output is correct
7 Correct 52 ms 7180 KB Output is correct
8 Correct 76 ms 7268 KB Output is correct
9 Correct 61 ms 7272 KB Output is correct
10 Correct 56 ms 7180 KB Output is correct
11 Correct 60 ms 7240 KB Output is correct
12 Correct 51 ms 7240 KB Output is correct
13 Correct 54 ms 7280 KB Output is correct
14 Correct 569 ms 34488 KB Output is correct
15 Correct 58 ms 7256 KB Output is correct
16 Correct 466 ms 34140 KB Output is correct
17 Correct 478 ms 33816 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 1240 KB Output is correct
3 Correct 5 ms 1240 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1240 KB Output is correct
17 Correct 55 ms 7236 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 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 456 ms 67484 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 472 ms 35760 KB Output is correct
31 Correct 504 ms 35088 KB Output is correct
32 Correct 455 ms 35064 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 525 ms 35032 KB Output is correct
35 Correct 515 ms 35040 KB Output is correct
36 Correct 536 ms 34936 KB Output is correct
37 Correct 615 ms 34920 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 48 ms 7292 KB Output is correct
40 Correct 51 ms 7252 KB Output is correct
41 Correct 50 ms 7228 KB Output is correct
42 Correct 52 ms 7224 KB Output is correct
43 Correct 49 ms 7216 KB Output is correct
44 Correct 48 ms 7216 KB Output is correct
45 Correct 46 ms 7220 KB Output is correct
46 Correct 53 ms 7232 KB Output is correct
47 Correct 47 ms 7172 KB Output is correct
48 Correct 73 ms 7248 KB Output is correct
49 Correct 54 ms 7260 KB Output is correct
50 Correct 49 ms 7268 KB Output is correct
51 Correct 483 ms 34872 KB Output is correct
52 Correct 446 ms 34864 KB Output is correct
53 Correct 575 ms 34924 KB Output is correct
54 Correct 57 ms 7236 KB Output is correct
55 Correct 47 ms 7228 KB Output is correct
56 Correct 196 ms 40616 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 53 ms 7272 KB Output is correct
59 Correct 59 ms 7232 KB Output is correct
60 Correct 640 ms 34760 KB Output is correct
61 Correct 55 ms 7248 KB Output is correct
62 Correct 62 ms 7216 KB Output is correct
63 Correct 52 ms 7180 KB Output is correct
64 Correct 76 ms 7268 KB Output is correct
65 Correct 61 ms 7272 KB Output is correct
66 Correct 56 ms 7180 KB Output is correct
67 Correct 60 ms 7240 KB Output is correct
68 Correct 51 ms 7240 KB Output is correct
69 Correct 54 ms 7280 KB Output is correct
70 Correct 569 ms 34488 KB Output is correct
71 Correct 58 ms 7256 KB Output is correct
72 Correct 466 ms 34140 KB Output is correct
73 Correct 478 ms 33816 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 324 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 5 ms 1344 KB Output is correct
80 Correct 643 ms 68976 KB Output is correct
81 Correct 645 ms 68912 KB Output is correct
82 Correct 605 ms 68944 KB Output is correct
83 Correct 615 ms 69000 KB Output is correct
84 Correct 587 ms 68864 KB Output is correct
85 Correct 592 ms 68888 KB Output is correct
86 Correct 190 ms 43116 KB Output is correct
87 Correct 1 ms 340 KB Output is correct