Submission #243702

# Submission time Handle Problem Language Result Execution time Memory
243702 2020-07-01T15:16:01 Z neihcr7j Strange Device (APIO19_strange_device) C++14
100 / 100
899 ms 69016 KB
#include<bits/stdc++.h>

#define maxn 100005

using namespace std;
typedef long long ll;

ll n, a, b;
ll ret;

int main(){
  #define TASK "ABC"
//  freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n >> a >> b;

  ret = __gcd(a, b + 1);
  ret = a / ret;

  if (sqrt(ret) * sqrt(b) > 1e9) {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
      ll l, r;
      cin >> l >> r;
      ans += r + 1;
      ans -= l;
    }

    cout << ans;
    return 0;
  }

  ret *= b;

  vector < pair < ll, int > > q;

  for (int i = 0; i < n; ++i) {
    ll l, r;
    cin >> l >> r;

    if (r - l + 1 >= ret) {
      cout << ret;
      return 0;
    }

    l %= ret; r %= ret;

    if (l <= r) {
      q.push_back({l, 1});
      q.push_back({r + 1, -1});
    }
    else {
      q.push_back({0, 1});
      q.push_back({r + 1, -1});

      q.push_back({l, 1});
      q.push_back({ret, -1});
    }
  }

  sort(q.begin(), q.end());

  ll ans = 0, cnt = 0;
  for (int i = 0; i + 1 < q.size(); ++i) {
    cnt += q[i].second;
    if (cnt)
      ans += q[i + 1].first - q[i].first;
  }

  cout << ans;

  return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:65:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i + 1 < q.size(); ++i) {
                   ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 12 ms 1408 KB Output is correct
3 Correct 11 ms 1408 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 88 ms 7276 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 480 ms 33572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 675 ms 33500 KB Output is correct
3 Correct 697 ms 33472 KB Output is correct
4 Correct 655 ms 33472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 675 ms 33500 KB Output is correct
3 Correct 697 ms 33472 KB Output is correct
4 Correct 655 ms 33472 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 700 ms 33452 KB Output is correct
7 Correct 710 ms 33472 KB Output is correct
8 Correct 707 ms 33472 KB Output is correct
9 Correct 808 ms 33692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 675 ms 33500 KB Output is correct
3 Correct 697 ms 33472 KB Output is correct
4 Correct 655 ms 33472 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 70 ms 7276 KB Output is correct
7 Correct 70 ms 7396 KB Output is correct
8 Correct 66 ms 7396 KB Output is correct
9 Correct 71 ms 7396 KB Output is correct
10 Correct 67 ms 7276 KB Output is correct
11 Correct 77 ms 7272 KB Output is correct
12 Correct 73 ms 7276 KB Output is correct
13 Correct 75 ms 7276 KB Output is correct
14 Correct 69 ms 7256 KB Output is correct
15 Correct 76 ms 7272 KB Output is correct
16 Correct 84 ms 7276 KB Output is correct
17 Correct 78 ms 7400 KB Output is correct
18 Correct 722 ms 33476 KB Output is correct
19 Correct 676 ms 33472 KB Output is correct
20 Correct 837 ms 33604 KB Output is correct
21 Correct 82 ms 7272 KB Output is correct
22 Correct 62 ms 7280 KB Output is correct
23 Correct 198 ms 21076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 86 ms 7148 KB Output is correct
3 Correct 83 ms 7284 KB Output is correct
4 Correct 837 ms 33600 KB Output is correct
5 Correct 74 ms 7396 KB Output is correct
6 Correct 74 ms 7296 KB Output is correct
7 Correct 82 ms 7396 KB Output is correct
8 Correct 84 ms 7332 KB Output is correct
9 Correct 83 ms 7400 KB Output is correct
10 Correct 85 ms 7396 KB Output is correct
11 Correct 82 ms 7532 KB Output is correct
12 Correct 74 ms 7396 KB Output is correct
13 Correct 79 ms 7272 KB Output is correct
14 Correct 824 ms 33596 KB Output is correct
15 Correct 88 ms 7276 KB Output is correct
16 Correct 670 ms 33352 KB Output is correct
17 Correct 899 ms 33592 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 12 ms 1408 KB Output is correct
3 Correct 11 ms 1408 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 88 ms 7276 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 480 ms 33572 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 675 ms 33500 KB Output is correct
31 Correct 697 ms 33472 KB Output is correct
32 Correct 655 ms 33472 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 700 ms 33452 KB Output is correct
35 Correct 710 ms 33472 KB Output is correct
36 Correct 707 ms 33472 KB Output is correct
37 Correct 808 ms 33692 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 70 ms 7276 KB Output is correct
40 Correct 70 ms 7396 KB Output is correct
41 Correct 66 ms 7396 KB Output is correct
42 Correct 71 ms 7396 KB Output is correct
43 Correct 67 ms 7276 KB Output is correct
44 Correct 77 ms 7272 KB Output is correct
45 Correct 73 ms 7276 KB Output is correct
46 Correct 75 ms 7276 KB Output is correct
47 Correct 69 ms 7256 KB Output is correct
48 Correct 76 ms 7272 KB Output is correct
49 Correct 84 ms 7276 KB Output is correct
50 Correct 78 ms 7400 KB Output is correct
51 Correct 722 ms 33476 KB Output is correct
52 Correct 676 ms 33472 KB Output is correct
53 Correct 837 ms 33604 KB Output is correct
54 Correct 82 ms 7272 KB Output is correct
55 Correct 62 ms 7280 KB Output is correct
56 Correct 198 ms 21076 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 86 ms 7148 KB Output is correct
59 Correct 83 ms 7284 KB Output is correct
60 Correct 837 ms 33600 KB Output is correct
61 Correct 74 ms 7396 KB Output is correct
62 Correct 74 ms 7296 KB Output is correct
63 Correct 82 ms 7396 KB Output is correct
64 Correct 84 ms 7332 KB Output is correct
65 Correct 83 ms 7400 KB Output is correct
66 Correct 85 ms 7396 KB Output is correct
67 Correct 82 ms 7532 KB Output is correct
68 Correct 74 ms 7396 KB Output is correct
69 Correct 79 ms 7272 KB Output is correct
70 Correct 824 ms 33596 KB Output is correct
71 Correct 88 ms 7276 KB Output is correct
72 Correct 670 ms 33352 KB Output is correct
73 Correct 899 ms 33592 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 4 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 11 ms 1408 KB Output is correct
80 Correct 845 ms 53096 KB Output is correct
81 Correct 821 ms 52928 KB Output is correct
82 Correct 836 ms 53008 KB Output is correct
83 Correct 782 ms 68892 KB Output is correct
84 Correct 783 ms 69016 KB Output is correct
85 Correct 795 ms 52292 KB Output is correct
86 Correct 216 ms 26708 KB Output is correct
87 Correct 5 ms 384 KB Output is correct