QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446008#8528. Chordsucup-team3734WA 0ms3508kbC++233.2kb2024-06-16 19:09:302024-06-16 19:09:30

Judging History

你现在查看的是最新测评结果

  • [2024-06-16 19:09:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3508kb
  • [2024-06-16 19:09:30]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double lf;

bool between(int x, int l, int r) {
    if (l <= r) {
        return l <= x && x <= r;
    } else {
        return l <= x || x <= r;
    }
}

int sub(int x, int y, int mod) {
    x -= y;
    if (x < 0) {
        x += mod;
    }
    return x;
}

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng(1337);

vector<pair<int, int>> gen(int n) {
    vector<int> p(2 * n);
    iota(p.begin(), p.end(), 0);
    shuffle(p.begin(), p.end(), rng);
    vector<pair<int, int>> res;
    for (int i = 0; i < n; i++) {
        auto a = p[2 * i];
        auto b = p[2 * i + 1];
        if (a > b) {
            swap(a, b);
        }
        res.emplace_back(a, b);
    }
    return res;
}

vector<pair<int, int>> cut(const vector<pair<int, int>>& ch, int x) {
    int n = 2 * (int) ch.size();
    vector<pair<int, int>> res;
    for (auto [a, b] : ch) {
        if (between(x, a, b)) {
            continue;
        } else {
            res.emplace_back(sub(a, x, n), sub(b, x, n));
            assert(res.back().first < res.back().second);
        }
    }
    return res;
}

int max_non_int(vector<tuple<int, int, int>> segs) {
    if (segs.size() == 0) {
        return 0;
    }
    auto cmp = [](auto a, auto b) {
        return get<1>(a) < get<1>(b);
    };
    sort(segs.begin(), segs.end(), cmp);
    int n = (int) segs.size();
    vector<int> dp(n + 1, 0);
    for (int i = 0; i < n; i++) {
        auto [l, r, w] = segs[i];
        dp[i + 1] = max(dp[i + 1], dp[i]);
        auto it = lower_bound(segs.begin(), segs.end(), make_tuple(0, l, 0), cmp) - segs.begin();
        dp[i + 1] = max(dp[i + 1], w + dp[it]);
    }
    return dp[n];
}

int solve_seg(vector<pair<int, int>> ch, int n) {
    ch.emplace_back(-1, n);
    int m = (int) ch.size();
    sort(ch.begin(), ch.end(), [](auto a, auto b) {
        return a.second - a.first < b.second - b.first;
    });
    assert(ch.back().first == -1 && ch.back().second == n);
    vector<int> dp(m, 1);
    for (int i = 0; i < m; i++) {
        auto [l, r] = ch[i];
        vector<tuple<int, int, int>> cur;
        for (int j = 0; j < i; ++j) {
            auto [a, b] = ch[j];
            if (l < a && b < r) {
                cur.emplace_back(a, b, dp[j]);
            }
        }
        dp[i] = max(dp[i], 1 + max_non_int(std::move(cur)));
    }
    return dp[m - 1] - 1;
}

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> ch(n);
    for (int i = 0; i < n; i++) {
        cin >> ch[i].first >> ch[i].second;
        ch[i].first--;
        ch[i].second--;
    }
    // vector<pair<int, int>> ch = gen(n);
    
    int ans = 0;
    for (int it = 0; it < 10; ++it) {
        auto nch = cut(ch, (int) rng() % (2 * n));
        ans = max(ans, solve_seg(std::move(nch), 2 * n));
    }
    cout << ans << '\n';
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3500kb

input:

5
1 2
4 10
7 9
3 5
6 8

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3508kb

input:

1
1 2

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'