답안 #1044775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1044775 2024-08-05T13:25:01 Z vjudge1 이상한 기계 (APIO19_strange_device) C++17
10 / 100
620 ms 85872 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 3e4 + 100;

#define int long long
set<pair<int,int>> st;
void add_seg(int l, int r) {
    if (st.size()) {
        auto x = st.upper_bound(make_pair(l, 0));
        if (x != st.begin()) {
            x--;
            if ((*x).f <= l && r <= (*x).s)
                return ;            
        }
    }

    if (st.size()) {
        auto x = st.lower_bound(make_pair(l, 0));
        if (x != st.begin() && (*prev(x)).s >= l)
            x--;

        while (x != st.end() && (*x).f <= r) {
            l = min(l, (*x).f);
            r = max(r, (*x).s);
            x = st.erase(x);
        }
    }
    st.insert({l, r});
}

signed main() {
    fast
    ll n, A, B;
    cin >> n >> A >> B;

    if ((((long long)1e9) * ((long long)1e9) + A - 1LL) / A <= B) {
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int l, r;
            cin >> l >> r;
            add_seg(l, r);
        }

        for (auto u : st)
            ans += u.s - u.f + 1;
        cout << ans << "\n";
        return 0;
    }

    A *= B;

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

        if (r - l + 1 >= A) {
            cout << A << "\n";
            return 0;
        }

        int x = l % A;
        int y = r % A;
        if (y < x || r - l + 1 >= A) {
            add_seg(x, A-1);
            add_seg(0, y);
        } else
            add_seg(x, y);
    }

    ll ans = 0;
    for (auto u : st)
        ans += u.s - u.f + 1;
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 1072 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 160 ms 6680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 551 ms 75012 KB Output is correct
3 Incorrect 554 ms 85760 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 551 ms 75012 KB Output is correct
3 Incorrect 554 ms 85760 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 551 ms 75012 KB Output is correct
3 Incorrect 554 ms 85760 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 51 ms 7812 KB Output is correct
3 Correct 50 ms 7760 KB Output is correct
4 Correct 561 ms 85864 KB Output is correct
5 Correct 68 ms 9548 KB Output is correct
6 Correct 50 ms 9544 KB Output is correct
7 Correct 49 ms 9512 KB Output is correct
8 Correct 59 ms 9556 KB Output is correct
9 Correct 53 ms 9588 KB Output is correct
10 Correct 62 ms 9552 KB Output is correct
11 Correct 48 ms 9556 KB Output is correct
12 Correct 41 ms 9404 KB Output is correct
13 Correct 48 ms 9552 KB Output is correct
14 Correct 620 ms 85872 KB Output is correct
15 Incorrect 52 ms 9552 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 1072 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -