Submission #783438

# Submission time Handle Problem Language Result Execution time Memory
783438 2023-07-14T23:32:12 Z makanhulia Strange Device (APIO19_strange_device) C++17
10 / 100
562 ms 62920 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int INFF = 2e18;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int n, a, b;
        cin >> n >> a >> b;

        /*
        0 0 0 0
        1 1 1 1
        2 2 2 2
        4 3 1 0
        5 4 2 1
        6 5 0 2
        8 6 2 0
        9 7 0 1
        10 8 1 2
        12 9 0 0

        0 0 0 0
        1 1 1 1
        2 2 0 2
        3 3 1 3
        5 4 1 0
        6 5 0 1
        7 6 1 2
        8 7 0 3
        10 8 0 0

        4 2

        0 0 0 0
        1 1 1 1
        3 2 3 0
        4 3 0 1
        6 4 2 0
        7 5 3 1
        9 6 1 2
        10 7 2 1
        12 8 0 0

        4 1
        0 0
        2 1
        4 2

        3 2
        0 0
        1 1
        3 2
        4 3
        6 3

        3 1

        0 0
        2 1
        4 2
        6 3


        setiap b, nambah b + 1


        */

        int len = lcm(a, b + 1) / (b + 1) * b;

        set<pair<int, int>> seg;
        
        auto insert = [&](int l, int r) {
                auto it = seg.lower_bound({l, 0});
                if (!seg.empty() && it != seg.begin()) --it;

                int mnl = l, mxr = r;
                vector<pair<int, int>> del;

                for (; it != seg.end(); it++) {
                        if (it->fi > r) break;

                        if (it->fi < l && it->se >= l) {
                                del.push_back(*it);
                                mnl = min(mnl, it->fi);
                                mxr = max(mxr, it->se);
                        }

                        if (it->fi >= l && it->fi <= r) {
                                del.push_back(*it);
                                mnl = min(mnl, it->fi);
                                mxr = max(mxr, it->se);
                        }
                }

                for (auto p : del) seg.erase(p);

                seg.insert({mnl, mxr});
        };

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

                if (a <= INFF / b && r - l + 1 >= a * b) {
                        cout << a * b << '\n';
                        return 0;
                }
                
                if (a <= INFF / b) {
                        l %= a * b;
                        r %= a * b;
                }

                if (l <= r) {
                        insert(l, r);
                } else {
                        assert(a <= INFF / b);

                        insert(l, a * b - 1);
                        insert(0, r);
                }
        }
        
        int ans = 0;
        for (auto [l, r] : seg) ans += r - l + 1;

        cout << ans << '\n';

        return 0;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:77:13: warning: unused variable 'len' [-Wunused-variable]
   77 |         int len = lcm(a, b + 1) / (b + 1) * b;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 852 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 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 0 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 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 244 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 511 ms 62892 KB Output is correct
3 Incorrect 537 ms 62920 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 511 ms 62892 KB Output is correct
3 Incorrect 537 ms 62920 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 511 ms 62892 KB Output is correct
3 Incorrect 537 ms 62920 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 57 ms 6392 KB Output is correct
3 Correct 52 ms 6448 KB Output is correct
4 Correct 516 ms 62868 KB Output is correct
5 Correct 50 ms 6492 KB Output is correct
6 Correct 50 ms 6540 KB Output is correct
7 Correct 50 ms 6532 KB Output is correct
8 Correct 50 ms 6508 KB Output is correct
9 Correct 49 ms 6552 KB Output is correct
10 Correct 44 ms 6468 KB Output is correct
11 Correct 44 ms 6516 KB Output is correct
12 Correct 45 ms 6504 KB Output is correct
13 Correct 49 ms 6512 KB Output is correct
14 Correct 562 ms 62768 KB Output is correct
15 Incorrect 48 ms 6472 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 852 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -