Submission #240487

# Submission time Handle Problem Language Result Execution time Memory
240487 2020-06-19T17:21:01 Z valerikk Strange Device (APIO19_strange_device) C++14
65 / 100
815 ms 40260 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 2e18 + 7;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    a /= __gcd(a, b + 1);
    int p = INF / b <= a ? INF : a * b;
    vector<pair<int, int>> arr;
    while (n--) {
        int l, r;
        cin >> l >> r;
        l %= p;
        r %= p;
        if (l <= r) {
            arr.emplace_back(l, 1);
            arr.emplace_back(r + 1, -1);
        } else {
            arr.emplace_back(0, 1);
            arr.emplace_back(r + 1, -1);
            arr.emplace_back(l, 1);
            arr.emplace_back(p, -1);
        }
    }
    sort(arr.begin(), arr.end());
    int ans = 0, bal = 0;
    for (int i = 0; i + 1 < arr.size(); i++) {
        bal += arr[i].second;
        if (bal > 0) ans += arr[i + 1].first - arr[i].first;
    }
    cout << ans;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:33:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i + 1 < arr.size(); i++) {
                     ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 11 ms 996 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 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 11 ms 1024 KB Output is correct
17 Correct 76 ms 4724 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 437 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 633 ms 33340 KB Output is correct
3 Correct 637 ms 33352 KB Output is correct
4 Correct 598 ms 33272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 633 ms 33340 KB Output is correct
3 Correct 637 ms 33352 KB Output is correct
4 Correct 598 ms 33272 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 650 ms 33524 KB Output is correct
7 Correct 624 ms 33344 KB Output is correct
8 Correct 623 ms 33340 KB Output is correct
9 Correct 776 ms 33520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 633 ms 33340 KB Output is correct
3 Correct 637 ms 33352 KB Output is correct
4 Correct 598 ms 33272 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 65 ms 4588 KB Output is correct
7 Correct 67 ms 4588 KB Output is correct
8 Correct 69 ms 4636 KB Output is correct
9 Correct 65 ms 4660 KB Output is correct
10 Correct 61 ms 4724 KB Output is correct
11 Correct 66 ms 4584 KB Output is correct
12 Correct 65 ms 4544 KB Output is correct
13 Correct 70 ms 4596 KB Output is correct
14 Correct 63 ms 4588 KB Output is correct
15 Correct 79 ms 4568 KB Output is correct
16 Correct 71 ms 4648 KB Output is correct
17 Correct 66 ms 4588 KB Output is correct
18 Correct 651 ms 33344 KB Output is correct
19 Correct 596 ms 40128 KB Output is correct
20 Correct 757 ms 40260 KB Output is correct
21 Correct 80 ms 7396 KB Output is correct
22 Correct 67 ms 7324 KB Output is correct
23 Correct 184 ms 26736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 70 ms 4588 KB Output is correct
3 Correct 72 ms 4588 KB Output is correct
4 Correct 815 ms 33348 KB Output is correct
5 Correct 72 ms 4588 KB Output is correct
6 Correct 71 ms 4588 KB Output is correct
7 Correct 73 ms 4584 KB Output is correct
8 Correct 72 ms 4588 KB Output is correct
9 Correct 68 ms 4588 KB Output is correct
10 Correct 77 ms 4584 KB Output is correct
11 Correct 74 ms 4588 KB Output is correct
12 Correct 64 ms 4588 KB Output is correct
13 Correct 74 ms 4584 KB Output is correct
14 Correct 737 ms 33344 KB Output is correct
15 Correct 74 ms 4588 KB Output is correct
16 Correct 614 ms 33344 KB Output is correct
17 Correct 641 ms 33340 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 11 ms 1024 KB Output is correct
3 Correct 11 ms 996 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 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 11 ms 1024 KB Output is correct
17 Correct 76 ms 4724 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Incorrect 5 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -