Submission #120571

# Submission time Handle Problem Language Result Execution time Memory
120571 2019-06-25T03:28:24 Z IOrtroiii Strange Device (APIO19_strange_device) C++14
100 / 100
991 ms 33464 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll inf = 4e18;

ll mul(ll a, ll b) {
   if (a > (inf / b)) {
      return inf;
   } else {
      return a * b;
   }
}

int main() {
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   ll A, B;
   cin >> A >> B;
   A /= __gcd(A, B + 1);
   ll C = mul(A, B);
   vector<pair<ll, int>> go;
   for (int i = 0; i < n; ++i) {
      ll l, r;
      cin >> l >> r;
      if (r - l + 1 >= C) {
         go.emplace_back(0, 1);
         go.emplace_back(C, -1);
      } else if (l % C <= r % C) {
         l %= C, r %= C;
         go.emplace_back(l, 1);
         go.emplace_back(r + 1, -1);
      } else {
         l %= C, r %= C;
         go.emplace_back(l, 1);
         go.emplace_back(C, -1);
         go.emplace_back(0, 1);
         go.emplace_back(r + 1, -1);
      }
   }
   sort(go.begin(), go.end());
   ll ans = 0;
   int l = 0;
   int cnt = 0;
   while (l < go.size()) {
      int r = l;
      while (r < go.size() && go[r].first == go[l].first) {
         cnt += go[r++].second;
      }
      if (cnt) {
         ans += go[r].first - go[l].first;
      }
      l = r;
   }
   cout << ans << "\n";
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:47:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while (l < go.size()) {
           ~~^~~~~~~~~~~
strange_device.cpp:49:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       while (r < go.size() && go[r].first == go[l].first) {
              ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 9 ms 1016 KB Output is correct
17 Correct 88 ms 4584 KB Output is correct
18 Correct 2 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 546 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
2 Correct 774 ms 33356 KB Output is correct
3 Correct 825 ms 33276 KB Output is correct
4 Correct 793 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
2 Correct 774 ms 33356 KB Output is correct
3 Correct 825 ms 33276 KB Output is correct
4 Correct 793 ms 33344 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 812 ms 33352 KB Output is correct
7 Correct 779 ms 33464 KB Output is correct
8 Correct 797 ms 33284 KB Output is correct
9 Correct 898 ms 33336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
2 Correct 774 ms 33356 KB Output is correct
3 Correct 825 ms 33276 KB Output is correct
4 Correct 793 ms 33344 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 75 ms 4560 KB Output is correct
7 Correct 79 ms 4584 KB Output is correct
8 Correct 77 ms 4584 KB Output is correct
9 Correct 78 ms 4584 KB Output is correct
10 Correct 73 ms 4584 KB Output is correct
11 Correct 78 ms 4584 KB Output is correct
12 Correct 75 ms 4584 KB Output is correct
13 Correct 85 ms 4584 KB Output is correct
14 Correct 77 ms 4588 KB Output is correct
15 Correct 89 ms 4588 KB Output is correct
16 Correct 89 ms 4584 KB Output is correct
17 Correct 79 ms 4720 KB Output is correct
18 Correct 803 ms 33328 KB Output is correct
19 Correct 773 ms 33320 KB Output is correct
20 Correct 919 ms 33296 KB Output is correct
21 Correct 88 ms 4604 KB Output is correct
22 Correct 71 ms 4712 KB Output is correct
23 Correct 224 ms 16948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 85 ms 4512 KB Output is correct
3 Correct 88 ms 4712 KB Output is correct
4 Correct 988 ms 33316 KB Output is correct
5 Correct 86 ms 4632 KB Output is correct
6 Correct 85 ms 4584 KB Output is correct
7 Correct 89 ms 4556 KB Output is correct
8 Correct 88 ms 4540 KB Output is correct
9 Correct 82 ms 4584 KB Output is correct
10 Correct 90 ms 4584 KB Output is correct
11 Correct 86 ms 4588 KB Output is correct
12 Correct 78 ms 4580 KB Output is correct
13 Correct 91 ms 4588 KB Output is correct
14 Correct 892 ms 33276 KB Output is correct
15 Correct 90 ms 4540 KB Output is correct
16 Correct 742 ms 33256 KB Output is correct
17 Correct 775 ms 33328 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 9 ms 1016 KB Output is correct
17 Correct 88 ms 4584 KB Output is correct
18 Correct 2 ms 296 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 1 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 546 ms 33344 KB Output is correct
29 Correct 3 ms 508 KB Output is correct
30 Correct 774 ms 33356 KB Output is correct
31 Correct 825 ms 33276 KB Output is correct
32 Correct 793 ms 33344 KB Output is correct
33 Correct 2 ms 252 KB Output is correct
34 Correct 812 ms 33352 KB Output is correct
35 Correct 779 ms 33464 KB Output is correct
36 Correct 797 ms 33284 KB Output is correct
37 Correct 898 ms 33336 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 75 ms 4560 KB Output is correct
40 Correct 79 ms 4584 KB Output is correct
41 Correct 77 ms 4584 KB Output is correct
42 Correct 78 ms 4584 KB Output is correct
43 Correct 73 ms 4584 KB Output is correct
44 Correct 78 ms 4584 KB Output is correct
45 Correct 75 ms 4584 KB Output is correct
46 Correct 85 ms 4584 KB Output is correct
47 Correct 77 ms 4588 KB Output is correct
48 Correct 89 ms 4588 KB Output is correct
49 Correct 89 ms 4584 KB Output is correct
50 Correct 79 ms 4720 KB Output is correct
51 Correct 803 ms 33328 KB Output is correct
52 Correct 773 ms 33320 KB Output is correct
53 Correct 919 ms 33296 KB Output is correct
54 Correct 88 ms 4604 KB Output is correct
55 Correct 71 ms 4712 KB Output is correct
56 Correct 224 ms 16948 KB Output is correct
57 Correct 3 ms 376 KB Output is correct
58 Correct 85 ms 4512 KB Output is correct
59 Correct 88 ms 4712 KB Output is correct
60 Correct 988 ms 33316 KB Output is correct
61 Correct 86 ms 4632 KB Output is correct
62 Correct 85 ms 4584 KB Output is correct
63 Correct 89 ms 4556 KB Output is correct
64 Correct 88 ms 4540 KB Output is correct
65 Correct 82 ms 4584 KB Output is correct
66 Correct 90 ms 4584 KB Output is correct
67 Correct 86 ms 4588 KB Output is correct
68 Correct 78 ms 4580 KB Output is correct
69 Correct 91 ms 4588 KB Output is correct
70 Correct 892 ms 33276 KB Output is correct
71 Correct 90 ms 4540 KB Output is correct
72 Correct 742 ms 33256 KB Output is correct
73 Correct 775 ms 33328 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 9 ms 1016 KB Output is correct
80 Correct 976 ms 33300 KB Output is correct
81 Correct 991 ms 33328 KB Output is correct
82 Correct 899 ms 33248 KB Output is correct
83 Correct 885 ms 33436 KB Output is correct
84 Correct 899 ms 33360 KB Output is correct
85 Correct 898 ms 33316 KB Output is correct
86 Correct 219 ms 16932 KB Output is correct
87 Correct 2 ms 376 KB Output is correct