Submission #1020184

# Submission time Handle Problem Language Result Execution time Memory
1020184 2024-07-11T16:29:52 Z avighna Strange Device (APIO19_strange_device) C++17
100 / 100
562 ms 97676 KB
#include <bits/stdc++.h>

typedef long long ll;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ll n, a, b;
  std::cin >> n >> a >> b;

  // w (B + 1) mod A = 0
  ll cycle = (b / std::gcd(a, b + 1) >= (ll(1e18) + 1) / a)
                 ? ll(1e18) + 1
                 : a / std::gcd(a, b + 1) * b;
  std::vector<std::pair<ll, ll>> ranges;
  std::map<ll, ll> mp;
  while (n--) {
    ll l, r;
    std::cin >> l >> r;
    if (r - l + 1 >= cycle) {
      std::cout << cycle << "\n";
      return 0;
    }
    ll _l = l % cycle, _r = r % cycle;
    if (_l > _r) {
      ranges.push_back({_l, cycle - 1});
      ranges.push_back({0, _r});
    } else {
      ranges.push_back({_l, _r});
    }
  }
  for (auto &[l, r] : ranges) {
    mp[l] = std::max(mp[l], r);
  }
  ll right = 0;
  ll ans = 0;
  for (auto &i : mp) {
    if (i.second < right) {
      continue;
    }
    right = std::max(right, i.first);
    ans += i.second - right + 1;
    right = i.second + 1;
  }
  std::cout << ans << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 4 ms 1380 KB Output is correct
3 Correct 4 ms 1504 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1392 KB Output is correct
17 Correct 51 ms 10400 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 199 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 489 ms 97608 KB Output is correct
3 Correct 509 ms 97620 KB Output is correct
4 Correct 497 ms 97524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 489 ms 97608 KB Output is correct
3 Correct 509 ms 97620 KB Output is correct
4 Correct 497 ms 97524 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 516 ms 97424 KB Output is correct
7 Correct 536 ms 97436 KB Output is correct
8 Correct 502 ms 97200 KB Output is correct
9 Correct 534 ms 97344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 489 ms 97608 KB Output is correct
3 Correct 509 ms 97620 KB Output is correct
4 Correct 497 ms 97524 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 40 ms 10464 KB Output is correct
7 Correct 53 ms 10116 KB Output is correct
8 Correct 44 ms 10304 KB Output is correct
9 Correct 45 ms 10188 KB Output is correct
10 Correct 41 ms 10300 KB Output is correct
11 Correct 39 ms 10116 KB Output is correct
12 Correct 42 ms 10180 KB Output is correct
13 Correct 46 ms 10184 KB Output is correct
14 Correct 42 ms 10184 KB Output is correct
15 Correct 49 ms 10184 KB Output is correct
16 Correct 49 ms 10308 KB Output is correct
17 Correct 63 ms 10184 KB Output is correct
18 Correct 487 ms 97196 KB Output is correct
19 Correct 551 ms 97208 KB Output is correct
20 Correct 553 ms 97212 KB Output is correct
21 Correct 39 ms 10276 KB Output is correct
22 Correct 45 ms 10180 KB Output is correct
23 Correct 80 ms 14012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 48 ms 10372 KB Output is correct
3 Correct 49 ms 10432 KB Output is correct
4 Correct 560 ms 97676 KB Output is correct
5 Correct 50 ms 10272 KB Output is correct
6 Correct 48 ms 10192 KB Output is correct
7 Correct 47 ms 10212 KB Output is correct
8 Correct 48 ms 10288 KB Output is correct
9 Correct 45 ms 10196 KB Output is correct
10 Correct 42 ms 10108 KB Output is correct
11 Correct 48 ms 10324 KB Output is correct
12 Correct 42 ms 10184 KB Output is correct
13 Correct 49 ms 10188 KB Output is correct
14 Correct 553 ms 97564 KB Output is correct
15 Correct 40 ms 10288 KB Output is correct
16 Correct 461 ms 97340 KB Output is correct
17 Correct 508 ms 97260 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 4 ms 1380 KB Output is correct
3 Correct 4 ms 1504 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1392 KB Output is correct
17 Correct 51 ms 10400 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 199 ms 29276 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 489 ms 97608 KB Output is correct
31 Correct 509 ms 97620 KB Output is correct
32 Correct 497 ms 97524 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 516 ms 97424 KB Output is correct
35 Correct 536 ms 97436 KB Output is correct
36 Correct 502 ms 97200 KB Output is correct
37 Correct 534 ms 97344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 40 ms 10464 KB Output is correct
40 Correct 53 ms 10116 KB Output is correct
41 Correct 44 ms 10304 KB Output is correct
42 Correct 45 ms 10188 KB Output is correct
43 Correct 41 ms 10300 KB Output is correct
44 Correct 39 ms 10116 KB Output is correct
45 Correct 42 ms 10180 KB Output is correct
46 Correct 46 ms 10184 KB Output is correct
47 Correct 42 ms 10184 KB Output is correct
48 Correct 49 ms 10184 KB Output is correct
49 Correct 49 ms 10308 KB Output is correct
50 Correct 63 ms 10184 KB Output is correct
51 Correct 487 ms 97196 KB Output is correct
52 Correct 551 ms 97208 KB Output is correct
53 Correct 553 ms 97212 KB Output is correct
54 Correct 39 ms 10276 KB Output is correct
55 Correct 45 ms 10180 KB Output is correct
56 Correct 80 ms 14012 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 48 ms 10372 KB Output is correct
59 Correct 49 ms 10432 KB Output is correct
60 Correct 560 ms 97676 KB Output is correct
61 Correct 50 ms 10272 KB Output is correct
62 Correct 48 ms 10192 KB Output is correct
63 Correct 47 ms 10212 KB Output is correct
64 Correct 48 ms 10288 KB Output is correct
65 Correct 45 ms 10196 KB Output is correct
66 Correct 42 ms 10108 KB Output is correct
67 Correct 48 ms 10324 KB Output is correct
68 Correct 42 ms 10184 KB Output is correct
69 Correct 49 ms 10188 KB Output is correct
70 Correct 553 ms 97564 KB Output is correct
71 Correct 40 ms 10288 KB Output is correct
72 Correct 461 ms 97340 KB Output is correct
73 Correct 508 ms 97260 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 4 ms 1480 KB Output is correct
80 Correct 553 ms 97244 KB Output is correct
81 Correct 529 ms 97360 KB Output is correct
82 Correct 554 ms 97356 KB Output is correct
83 Correct 562 ms 97516 KB Output is correct
84 Correct 554 ms 97204 KB Output is correct
85 Correct 528 ms 97464 KB Output is correct
86 Correct 85 ms 14268 KB Output is correct
87 Correct 1 ms 344 KB Output is correct