Submission #784516

# Submission time Handle Problem Language Result Execution time Memory
784516 2023-07-16T07:42:54 Z kebine Strange Device (APIO19_strange_device) C++17
100 / 100
1490 ms 81016 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
// #define i128 long long
#define i128 __int128_t

int n, a, b;
vector<pair<int, int>> sg;
const int maks = 1e18;

// i128 gcd(i128 a, i128 b) {
//   if (b == 0) return a;
//   return gcd(b, a%b);
// }

bool comp(pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first or (a.first == b.first and a.second < b.second));
}

signed main() {
  i128 temp;
  // int temp;
  i128 size;
  cin >> n >> a >> b;
  // temp = a*b;
  temp = ((i128)a/__gcd(a,b+1))*(i128)b;
  // if ((b+1 % a) == 0) size = b;
  // if (temp > maks) size = maks;
  // else size = temp;
  size = temp;

  int l, r;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    // cout << l << " " << r << endl;
    if (r - l + 1 >= size) {
      cout << (int)size << endl;
      return 0;
    } else if (l%size > r%size) {
      sg.push_back({l%size, 1});
      sg.push_back({size-1, 2});
      sg.push_back({0, 1});
      sg.push_back({r%size, 2});
    } else {
      sg.push_back({l%size, 1});
      sg.push_back({r%size, 2});
    }
  }
  sort(sg.begin(), sg.end(), comp);

  int cnt = 0, l2;
  vector<pair<int, int>> ans;
  for (int i = 0; i < sg.size(); i++) {
    // cout << sg[i].first << " " << sg[i].second << endl;
    if (sg[i].second == 1) {
      if (cnt == 0) l2 = sg[i].first;
      cnt++;
    } else cnt--;

    if (cnt == 0) {
      ans.push_back({l2, sg[i].first});
      // ans += sg[i].first-l2+1.;
    }
  }
  // cout << ans << endl;

  int res = 0;
  for (auto i: ans) {
    // cout << i.first << " " << i.second << endl;
    res += (i.second - i.first + 1);
  }
  cout << res << endl;

}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:54:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for (int i = 0; i < sg.size(); i++) {
      |                   ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 12 ms 972 KB Output is correct
3 Correct 12 ms 1004 KB Output is correct
4 Correct 0 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 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 212 KB Output is correct
16 Correct 12 ms 956 KB Output is correct
17 Correct 135 ms 7016 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 0 ms 212 KB Output is correct
3 Correct 1 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 2 ms 340 KB Output is correct
5 Correct 809 ms 33148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1272 ms 63660 KB Output is correct
3 Correct 1324 ms 63632 KB Output is correct
4 Correct 1305 ms 63664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1272 ms 63660 KB Output is correct
3 Correct 1324 ms 63632 KB Output is correct
4 Correct 1305 ms 63664 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1323 ms 63588 KB Output is correct
7 Correct 1298 ms 63604 KB Output is correct
8 Correct 1313 ms 63620 KB Output is correct
9 Correct 1452 ms 63860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1272 ms 63660 KB Output is correct
3 Correct 1324 ms 63632 KB Output is correct
4 Correct 1305 ms 63664 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 119 ms 6956 KB Output is correct
7 Correct 131 ms 7008 KB Output is correct
8 Correct 120 ms 6968 KB Output is correct
9 Correct 140 ms 6944 KB Output is correct
10 Correct 119 ms 6928 KB Output is correct
11 Correct 122 ms 6980 KB Output is correct
12 Correct 123 ms 6960 KB Output is correct
13 Correct 138 ms 6984 KB Output is correct
14 Correct 123 ms 7028 KB Output is correct
15 Correct 135 ms 6944 KB Output is correct
16 Correct 132 ms 6960 KB Output is correct
17 Correct 123 ms 6996 KB Output is correct
18 Correct 1322 ms 63648 KB Output is correct
19 Correct 1288 ms 63564 KB Output is correct
20 Correct 1477 ms 63792 KB Output is correct
21 Correct 133 ms 7004 KB Output is correct
22 Correct 113 ms 7012 KB Output is correct
23 Correct 380 ms 16924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 129 ms 6932 KB Output is correct
3 Correct 134 ms 7004 KB Output is correct
4 Correct 1467 ms 63604 KB Output is correct
5 Correct 131 ms 6960 KB Output is correct
6 Correct 159 ms 7008 KB Output is correct
7 Correct 141 ms 7008 KB Output is correct
8 Correct 135 ms 7004 KB Output is correct
9 Correct 130 ms 7000 KB Output is correct
10 Correct 138 ms 7036 KB Output is correct
11 Correct 133 ms 6984 KB Output is correct
12 Correct 122 ms 7040 KB Output is correct
13 Correct 139 ms 7008 KB Output is correct
14 Correct 1408 ms 63604 KB Output is correct
15 Correct 135 ms 6824 KB Output is correct
16 Correct 1315 ms 63664 KB Output is correct
17 Correct 1398 ms 63672 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 12 ms 972 KB Output is correct
3 Correct 12 ms 1004 KB Output is correct
4 Correct 0 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 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 212 KB Output is correct
16 Correct 12 ms 956 KB Output is correct
17 Correct 135 ms 7016 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 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 2 ms 340 KB Output is correct
28 Correct 809 ms 33148 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1272 ms 63660 KB Output is correct
31 Correct 1324 ms 63632 KB Output is correct
32 Correct 1305 ms 63664 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1323 ms 63588 KB Output is correct
35 Correct 1298 ms 63604 KB Output is correct
36 Correct 1313 ms 63620 KB Output is correct
37 Correct 1452 ms 63860 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 119 ms 6956 KB Output is correct
40 Correct 131 ms 7008 KB Output is correct
41 Correct 120 ms 6968 KB Output is correct
42 Correct 140 ms 6944 KB Output is correct
43 Correct 119 ms 6928 KB Output is correct
44 Correct 122 ms 6980 KB Output is correct
45 Correct 123 ms 6960 KB Output is correct
46 Correct 138 ms 6984 KB Output is correct
47 Correct 123 ms 7028 KB Output is correct
48 Correct 135 ms 6944 KB Output is correct
49 Correct 132 ms 6960 KB Output is correct
50 Correct 123 ms 6996 KB Output is correct
51 Correct 1322 ms 63648 KB Output is correct
52 Correct 1288 ms 63564 KB Output is correct
53 Correct 1477 ms 63792 KB Output is correct
54 Correct 133 ms 7004 KB Output is correct
55 Correct 113 ms 7012 KB Output is correct
56 Correct 380 ms 16924 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 129 ms 6932 KB Output is correct
59 Correct 134 ms 7004 KB Output is correct
60 Correct 1467 ms 63604 KB Output is correct
61 Correct 131 ms 6960 KB Output is correct
62 Correct 159 ms 7008 KB Output is correct
63 Correct 141 ms 7008 KB Output is correct
64 Correct 135 ms 7004 KB Output is correct
65 Correct 130 ms 7000 KB Output is correct
66 Correct 138 ms 7036 KB Output is correct
67 Correct 133 ms 6984 KB Output is correct
68 Correct 122 ms 7040 KB Output is correct
69 Correct 139 ms 7008 KB Output is correct
70 Correct 1408 ms 63604 KB Output is correct
71 Correct 135 ms 6824 KB Output is correct
72 Correct 1315 ms 63664 KB Output is correct
73 Correct 1398 ms 63672 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 300 KB Output is correct
77 Correct 1 ms 300 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 13 ms 1356 KB Output is correct
80 Correct 1468 ms 80280 KB Output is correct
81 Correct 1490 ms 81008 KB Output is correct
82 Correct 1474 ms 81016 KB Output is correct
83 Correct 1475 ms 80980 KB Output is correct
84 Correct 1449 ms 80368 KB Output is correct
85 Correct 1430 ms 80280 KB Output is correct
86 Correct 362 ms 26580 KB Output is correct
87 Correct 1 ms 212 KB Output is correct