結果

問題 No.2220 Range Insert & Point Mex
ユーザー kuhakukuhaku
提出日時 2023-09-13 15:04:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 9,816 bytes
コンパイル時間 3,507 ms
コンパイル使用メモリ 234,256 KB
実行使用メモリ 6,920 KB
最終ジャッジ日時 2023-09-13 15:04:48
合計ジャッジ時間 9,741 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 187 ms
6,728 KB
testcase_14 AC 182 ms
6,800 KB
testcase_15 AC 186 ms
6,712 KB
testcase_16 AC 190 ms
6,728 KB
testcase_17 AC 185 ms
6,752 KB
testcase_18 AC 184 ms
6,920 KB
testcase_19 AC 183 ms
6,752 KB
testcase_20 AC 189 ms
6,708 KB
testcase_21 AC 193 ms
6,700 KB
testcase_22 AC 197 ms
6,764 KB
testcase_23 AC 106 ms
6,736 KB
testcase_24 AC 79 ms
5,360 KB
testcase_25 AC 83 ms
6,212 KB
testcase_26 AC 94 ms
6,808 KB
testcase_27 AC 30 ms
4,380 KB
testcase_28 AC 52 ms
5,376 KB
testcase_29 AC 52 ms
5,428 KB
testcase_30 AC 50 ms
5,432 KB
testcase_31 AC 96 ms
6,680 KB
testcase_32 AC 82 ms
6,408 KB
testcase_33 AC 87 ms
6,176 KB
testcase_34 AC 115 ms
6,676 KB
testcase_35 AC 116 ms
6,696 KB
testcase_36 AC 116 ms
6,740 KB
testcase_37 AC 118 ms
6,752 KB
testcase_38 AC 104 ms
6,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "a.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/2220"
#line 2 "/home/kuhaku/atcoder/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
template <class T, class U>
bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 3 "/home/kuhaku/atcoder/github/algo/lib/math/pow.hpp"

std::int64_t safe_mod(std::int64_t a, std::int64_t mod) {
    a %= mod;
    return a >= 0 ? a : a + mod;
}

std::int64_t pow_int(std::int64_t a, std::int64_t n) {
    assert(n >= 0);
    std::int64_t res = 1, mul = a;
    for (; n > 0; n >>= 1) {
        if (n & 1) res *= mul;
        mul *= mul;
    }
    return res;
}

std::int64_t inv_mod(std::int64_t a, std::int64_t mod) {
    std::int64_t b = mod, u = 1, v = 0, t;
    while (b > 0) {
        t = a / b;
        std::swap(a -= t * b, b);
        std::swap(u -= t * v, v);
    }
    return u >= 0 ? u % mod : (mod - (-u) % mod) % mod;
}

std::int64_t pow_mod(std::int64_t a, std::int64_t n, std::int64_t mod) {
    if (n < 0) return inv_mod(pow_mod(a, -n, mod), mod);
    std::int64_t res = 1, mul = safe_mod(a, mod);
    for (; n > 0; n >>= 1) {
        if (n & 1) (res *= mul) %= mod;
        (mul *= mul) %= mod;
    }
    return res;
}

int ceil_pow2(std::int64_t n) {
    int x = 0;
    while ((std::uint64_t(1) << x) < (std::uint64_t)(n)) ++x;
    return x;
}

int floor_pow2(std::int64_t n) {
    int x = 0;
    while ((std::uint64_t(1) << (x + 1)) <= (std::uint64_t)(n)) ++x;
    return x;
}
#line 3 "/home/kuhaku/atcoder/github/algo/lib/segment_tree/monoid.hpp"

template <class T>
struct Add {
    using value_type = T;
    static constexpr T id = T(0);
    static constexpr T op(const T &lhs, const T &rhs) { return lhs + rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs + rhs;
    }
};

template <class T>
struct And {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::max();
    static constexpr T op(const T &lhs, const T &rhs) { return lhs & rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs & rhs;
    }
};

template <class T>
struct Or {
    using value_type = T;
    static constexpr T id = T(0);
    static constexpr T op(const T &lhs, const T &rhs) { return lhs | rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs | rhs;
    }
};

template <class T>
struct Xor {
    using value_type = T;
    static constexpr T id = T(0);
    static constexpr T op(const T &lhs, const T &rhs) { return lhs ^ rhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs ^ rhs;
    }
};

template <class T>
struct Min {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::max();
    static constexpr T op(const T &lhs, const T &rhs) { return std::min(lhs, rhs); }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return std::min((U)lhs, rhs);
    }
};

template <class T>
struct Max {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::min();
    static constexpr T op(const T &lhs, const T &rhs) { return std::max(lhs, rhs); }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return std::max((U)lhs, rhs);
    }
};

template <class T>
struct Update {
    using value_type = T;
    static constexpr T id = std::numeric_limits<T>::max();
    static constexpr T op(const T &lhs, const T &rhs) { return lhs == Update::id ? rhs : lhs; }

    template <class U>
    static constexpr U f(T lhs, U rhs) {
        return lhs == Update::id ? rhs : lhs;
    }
};

template <class T>
struct Affine {
    using value_type = std::pair<T, T>;
    static constexpr std::pair<T, T> id = std::pair<T, T>(1, 0);
    static constexpr std::pair<T, T> op(std::pair<T, T> lhs, std::pair<T, T> rhs) {
        return {lhs.first * rhs.first, lhs.first * rhs.second + lhs.second};
    }
};

template <class M>
struct Rev {
    using T = typename M::value_type;
    using value_type = T;
    static constexpr T id = M::id;
    static constexpr T op(T lhs, T rhs) { return M::op(rhs, lhs); }
};
#line 4 "/home/kuhaku/atcoder/github/algo/lib/segment_tree/dual_segment_tree.hpp"

/**
 * @brief 双対セグメント木
 *
 * @tparam M
 */
template <class M>
struct dual_segment_tree {
    using T = typename M::value_type;

    dual_segment_tree(int _n, T _e = M::id) { this->init(_n, _e); }

    void init(int n, T e) {
        this->_log = ceil_pow2(n);
        this->_size = 1 << this->_log;
        this->data.assign(this->_size << 1, e);
    }

    T at(int k) { return this->get(k); }
    T get(int k) {
        assert(0 <= k && k < this->_size);
        k += this->_size;
        for (int i = this->_log; i >= 1; --i) this->push(k >> i);
        return this->data[k];
    }

    void apply(int a, T val) { this->apply(a, a + 1, val); }
    void apply(int a, int b, T val) {
        assert(0 <= a && a <= this->_size);
        assert(0 <= b && b <= this->_size);
        a += this->_size, b += this->_size;
        for (int i = _log; i >= 1; --i) {
            if (((a >> i) << i) != a) this->push(a >> i);
            if (((b >> i) << i) != b) this->push((b - 1) >> i);
        }

        for (; a < b; a >>= 1, b >>= 1) {
            if (a & 1) this->all_apply(a++, val);
            if (b & 1) this->all_apply(--b, val);
        }
    }

  private:
    int _size, _log;
    std::vector<T> data;

    void all_apply(int k, T val) { this->data[k] = M::op(val, this->data[k]); }
    void push(int k) {
        this->all_apply(2 * k, this->data[k]);
        this->all_apply(2 * k + 1, this->data[k]);
        this->data[k] = M::id;
    }
};
#line 3 "/home/kuhaku/atcoder/github/algo/lib/template/macro.hpp"
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
#line 3 "/home/kuhaku/atcoder/github/algo/lib/template/sonic.hpp"
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }

    constexpr void operator()() const {}
} sonic;
#line 5 "/home/kuhaku/atcoder/github/algo/lib/template/atcoder.hpp"
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) {
        os << (it == v.begin() ? "" : " ") << *it;
    }
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
template <typename T, typename... Args>
auto make_vector(T x, int arg, Args... args) {
    if constexpr (sizeof...(args) == 0) return std::vector<T>(arg, x);
    else return std::vector(arg, make_vector<T>(x, args...));
}
void setp(int n) {
    std::cout << std::fixed << std::setprecision(n);
}
void Yes(bool is_correct = true) {
    std::cout << (is_correct ? "Yes" : "No") << '\n';
}
void No(bool is_not_correct = true) {
    Yes(!is_not_correct);
}
void YES(bool is_correct = true) {
    std::cout << (is_correct ? "YES" : "NO") << '\n';
}
void NO(bool is_not_correct = true) {
    YES(!is_not_correct);
}
void Takahashi(bool is_correct = true) {
    std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n';
}
void Aoki(bool is_not_correct = true) {
    Takahashi(!is_not_correct);
}
#line 4 "a.cpp"

struct Monoid {
    using T = std::pair<int, int>;
    using value_type = T;
    static constexpr T id = T(-1, -1);
    static constexpr T op(const T &lhs, const T &rhs) {
        if (rhs == id)
            return lhs;
        if (lhs == id)
            return rhs;
        if (rhs.second >= lhs.first)
            return {rhs.first, lhs.second};
        return rhs;
    }
};

int main(void) {
    int n;
    cin >> n;
    vector<tuple<int, int, int>> t(n);
    for (auto &[x, y, z] : t) cin >> x >> y >> z;
    int q;
    cin >> q;
    vector<int> x(q);
    cin >> x;
    dual_segment_tree<Monoid> st(q);
    rep (i, q) st.apply(i, {0, 1});
    sort(all(t), [](auto l, auto r) {
        return get<2>(l) < get<2>(r);
    });
    for (auto [l, r, a] : t) {
        int f = lower_bound(all(x), l) - x.begin();
        int g = upper_bound(all(x), r) - x.begin();
        st.apply(f, g, {a + 1, a + 2});
    }
    rep (i, q) {
        if (st.get(i).first == 0)
            co(st.get(i).second - 1);
        else
            co(0);
    }

    return 0;
}
0