QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395089#7108. Couleurucup-team055#AC ✓861ms16956kbC++236.6kb2024-04-21 03:42:132024-04-21 03:42:13

Judging History

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

  • [2024-04-21 03:42:13]
  • 评测
  • 测评结果:AC
  • 用时:861ms
  • 内存:16956kb
  • [2024-04-21 03:42:13]
  • 提交

answer

#include <bits/extc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
const ll INF = LLONG_MAX / 4;
#define rep(i, a, b) for(ll i = a; i < (b); i++)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) { if(a <= b) return 0; a = b; return 1; }
bool chmax(auto& a, auto b) { if(a >= b) return 0; a = b; return 1; }


#include <cassert>
#include <vector>


#include <cassert>
#include <numeric>
#include <type_traits>

namespace atcoder {

namespace internal {

#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

#else

template <class T> using is_integral = typename std::is_integral<T>;

template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;

#endif

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace atcoder


namespace atcoder {

template <class T> struct fenwick_tree {
    using U = internal::to_unsigned_t<T>;

  public:
    fenwick_tree() : _n(0) {}
    explicit fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

}  // namespace atcoder

struct T {
    ll cost = 0, n;
    atcoder::fenwick_tree<int> s;
    T(ll n = 0): n(n), s(n) {}
    void push_back(ll x) {
        cost += s.sum(x, n);
        s.add(x, 1);
    }
    void pop_back(ll x) {
        s.add(x, -1);
        cost -= s.sum(x, n);
    }
    void pop_front(ll x) {
        s.add(x, -1);
        cost -= s.sum(0, x);
    }
};
void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N), P(N);
    for(ll& a : A) cin >> a;
    for(ll& a : P) cin >> a;
    map<ll, ll> interval;
    multiset<ll> costs = {0};
    vector<T> cc(N);
    auto add = [&](ll l, ll r, T& t) {
        if(l > r) return;
        interval.emplace(l, r);
        costs.insert(t.cost);
        swap(cc[l], t);
    };
    auto push = [&](ll l, ll r) {
        if(l > r) return;
        {
            vector<ll> idx;
            rep(i, l, r + 1) idx.push_back(i);
            ranges::stable_sort(idx, {}, [&](ll i) { return A[i]; });
            rep(i, 0, sz(idx)) A[idx[i]] = i;
        }
        interval[l] = r;
        T t(r - l + 1);
        rep(i, l, r + 1) t.push_back(A[i]);
        add(l, r, t);
    };
    auto rem = [&](ll l, ll r) {
        auto& t = cc[l];
        interval.erase(l);
        costs.erase(costs.find(t.cost));
    };
    auto erase = [&](ll i) {
        auto p = --interval.upper_bound(i);
        auto [l, r] = *p;
        T& t = cc[l];
        rem(l, r);
        if(r - i < i - l) {
            for(ll j = r; j >= i; j--) t.pop_back(A[j]);
            add(l, i - 1, t);
            push(i + 1, r);
        }
        else {
            rep(j, l, i + 1) t.pop_front(A[j]);
            add(i + 1, r, t);
            push(l, i - 1);
        }
    };
    push(0, N - 1);
    vector<ll> ans;
    ll prev = 0;
    for(ll p : P) {
        prev = *rbegin(costs);
        ans.push_back(prev);
        p ^= prev;
        p--;
        erase(p);
    }
    rep(i, 0, N) cout << ans[i] << " \n"[i + 1 == N];
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    ll T;
    cin >> T;
    while(T--) solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0
20 11 7 2 0 0 0 0 0 0
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 861ms
memory: 16956kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0
12 12 10 10 4 4 4 2 1 0
20 16 9 5 3 3 3 0 0 0
22 14 8 8 5 5 2 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
19 12 7 4 4 2 2 1 0 0
20 18 8 3 1 1 0 0 0 0
45 21 21 10 3 3 3 0 0 0
17 11 8 2 1 1 1 0 0 0
13 4 1 0 0 0 0 0 0 0
29 27 22 15 9 7 4 3 1 0
26 16 9 2 1 1 1 1 1 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed