답안 #630001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630001 2022-08-15T14:01:10 Z leeh18 Meteors (POI11_met) C++17
74 / 100
880 ms 31532 KB
#include <bits/stdc++.h>

#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

using namespace std;
using namespace atcoder;

auto main() -> int {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    for (int i = 0; i < M; i++) {
        int o;
        cin >> o;
        g[o-1].push_back(i);
    }
    vector<int64_t> p(N);
    for (auto& x : p) {
        cin >> x;
    }
    int Q;
    cin >> Q;
    vector<tuple<int, int, int64_t>> vec(Q);
    for (auto& [l, r, a] : vec) {
        cin >> l >> r >> a;
        --l, --r;
    }
    vector<pair<int, int>> rng(N, make_pair(0, Q));
    while (any_of(begin(rng), end(rng), [](auto e) { return e.first < e.second; })) {
        vector<vector<int>> t(Q+1);
        for (int i = 0; i < N; i++) {
            auto [lo, hi] = rng[i];
            if (lo < hi) {
                auto mid = (lo + hi) / 2;
                t[mid].push_back(i);
            }
        }
        fenwick_tree<int64_t> ft(M+1);
        auto update = [&](int l, int r, int64_t val) { // [l, r] inclusive
            ft.add(l, val);
            ft.add(r+1, -val);
        };
        auto query = [&](int pos) {
            return ft.sum(0, pos+1);
        };
        for (int i = 0; i < Q; i++) {
            auto [l, r, a] = vec[i];
            if (l <= r) {
                update(l, r, a);
            } else {
                update(l, M-1, a);
                update(0, r, a);
            }
            for (auto v : t[i]) {
                auto sum = 0LL;
                for (auto x : g[v]) {
                    sum += query(x);
                }
                auto& [lo, hi] = rng[v];
                auto mid = (lo + hi) / 2;
                if (sum >= p[v]) {
                    hi = mid;
                } else {
                    lo = mid + 1;
                }
            }
        }
    }
    for (auto [lo, hi] : rng) {
        if (lo == Q) {
            cout << "NIE\n";
        } else {
            cout << lo + 1 << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 4112 KB Output is correct
2 Correct 102 ms 5740 KB Output is correct
3 Correct 87 ms 5044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 4720 KB Output is correct
2 Correct 96 ms 4784 KB Output is correct
3 Correct 119 ms 5932 KB Output is correct
4 Correct 27 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 4068 KB Output is correct
2 Correct 82 ms 5904 KB Output is correct
3 Correct 42 ms 2912 KB Output is correct
4 Correct 86 ms 5340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 3920 KB Output is correct
2 Correct 96 ms 4856 KB Output is correct
3 Correct 68 ms 4160 KB Output is correct
4 Correct 104 ms 6180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 880 ms 31532 KB Output is correct
2 Incorrect 576 ms 23512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 832 ms 30508 KB Output is correct
2 Incorrect 561 ms 22176 KB Output isn't correct
3 Halted 0 ms 0 KB -