QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#632536#9450. Balloon Robotucup-team133#AC ✓147ms6948kbC++236.1kb2024-10-12 13:31:542024-10-12 13:31:57

Judging History

你现在查看的是测评时间为 2024-10-12 13:31:57 的历史记录

  • [2024-10-14 16:41:29]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:141ms
  • 内存:6832kb
  • [2024-10-14 16:40:52]
  • hack成功,自动添加数据
  • (/hack/990)
  • [2024-10-12 13:31:57]
  • 评测
  • 测评结果:100
  • 用时:147ms
  • 内存:6948kb
  • [2024-10-12 13:31:54]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    for (std::string_view sep = ""; const auto& e : v) {
        os << std::exchange(sep, " ") << e;
    }
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) {
    return y < x and (x = std::forward<U>(y), true);
}

template <class T, class U = T> bool chmax(T& x, U&& y) {
    return x < y and (x = std::forward<U>(y), true);
}

template <class T> void mkuni(std::vector<T>& v) {
    std::ranges::sort(v);
    auto result = std::ranges::unique(v);
    v.erase(result.begin(), result.end());
}

template <class T> int lwb(const std::vector<T>& v, const T& x) {
    return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}

#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 {

// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
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

using namespace std;

using ll = long long;

const int INF = 1e9;
const ll IINF = 1e18;

void solve() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> s(n), a(p), b(p);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        s[i]--;
    }
    for (int i = 0; i < p; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
    }

    vector<int> c(p);
    for (int i = 0; i < p; i++) c[i] = (s[a[i]] - b[i] + 1LL * m * INF) % m;
    auto cand = c;
    mkuni(cand);
    int len = cand.size();
    atcoder::fenwick_tree<ll> ft_cnt(len), ft_sum(len);
    for (int i = 0; i < p; i++) {
        int x = lwb(cand, c[i]);
        ft_cnt.add(x, 1);
        ft_sum.add(x, c[i]);
    }
    ll ans = IINF;
    for (int i = 0; i < len; i++) {
        ll sum = 0;
        sum += ft_sum.sum(i + 1, len) - ft_cnt.sum(i + 1, len) * cand[i];
        sum += ft_sum.sum(0, i) + ft_cnt.sum(0, i) * (m - cand[i]);
        chmin(ans, sum);
    }

    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int T;
    cin >> T;
    for (; T--;) solve();
    return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

4
2 3 3
1 2
1 1
2 1
1 4
2 3 5
1 2
1 1
2 1
1 2
1 3
1 4
3 7 5
3 5 7
1 5
2 1
3 3
1 5
2 5
2 100 2
1 51
1 500
2 1000

output:

1
4
5
50

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 147ms
memory: 6948kb

input:

1004
22 9426 26
1165 5248 8331 9055 1161 7381 2188 7489 5131 8434 2166 3981 6302 7188 4858 856 7797 9129 7839 1676 25 9053
20 6
22 68
12 16
11 63
17 49
5 10
21 68
17 80
18 18
10 28
15 55
14 80
1 45
21 67
5 74
13 4
3 34
7 80
9 95
5 52
8 31
2 53
7 22
5 99
20 66
12 2
33 9526 92
558 7460 280 7952 5186 9...

output:

94067
360219
223074
30971
171844
312753
0
158169
294738
291604
115632
59327
221328
287851
30518
337118
181724
249419
66367
10347
208411
180496
287130
40736
264604
278208
33792
191523
111583
31867
21143
232153
149868
191831
238832
63626
258936
133059
105618
237774
53942
342921
275883
110295
149350
20...

result:

ok 1004 lines

Extra Test:

score: 0
Extra Test Passed