結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー SnowBeenDidingSnowBeenDiding
提出日時 2024-02-23 21:55:34
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 2,500 ms
コード長 10,304 bytes
コンパイル時間 5,042 ms
コンパイル使用メモリ 318,976 KB
実行使用メモリ 12,292 KB
最終ジャッジ日時 2024-09-29 06:27:43
合計ジャッジ時間 11,188 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 56 ms
8,352 KB
testcase_03 AC 17 ms
6,816 KB
testcase_04 AC 104 ms
6,824 KB
testcase_05 AC 82 ms
6,904 KB
testcase_06 AC 40 ms
6,820 KB
testcase_07 AC 84 ms
6,820 KB
testcase_08 AC 32 ms
6,816 KB
testcase_09 AC 181 ms
12,160 KB
testcase_10 AC 178 ms
12,156 KB
testcase_11 AC 178 ms
12,156 KB
testcase_12 AC 180 ms
12,164 KB
testcase_13 AC 173 ms
12,156 KB
testcase_14 AC 180 ms
12,160 KB
testcase_15 AC 180 ms
12,160 KB
testcase_16 AC 149 ms
12,160 KB
testcase_17 AC 141 ms
12,164 KB
testcase_18 AC 149 ms
12,160 KB
testcase_19 AC 150 ms
12,284 KB
testcase_20 AC 149 ms
12,156 KB
testcase_21 AC 149 ms
12,160 KB
testcase_22 AC 147 ms
12,160 KB
testcase_23 AC 137 ms
12,160 KB
testcase_24 AC 128 ms
12,160 KB
testcase_25 AC 127 ms
12,288 KB
testcase_26 AC 129 ms
12,160 KB
testcase_27 AC 128 ms
12,164 KB
testcase_28 AC 131 ms
12,288 KB
testcase_29 AC 130 ms
12,164 KB
testcase_30 AC 136 ms
12,292 KB
testcase_31 AC 150 ms
12,160 KB
testcase_32 AC 110 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
const long long MOD = 998244353;
// using mint = modint1000000007;
// const long long MOD = 1000000007;
// using mint = modint;//mint::set_mod(MOD);

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repeq(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define repreq(i, a, b) for (ll i = (ll)(a); i >= (ll)(b); i--)
#define endl '\n'  // fflush(stdout);
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define sortr(v) sort(v, greater<>())
#define pb push_back
#define pob pop_back
#define mp make_pair
#define mt make_tuple
#define FI first
#define SE second
#define ALL(v) (v).begin(), (v).end()
#define INFLL 3000000000000000100LL
#define INF 1000000100
#define PI acos(-1.0L)
#define TAU (PI * 2.0L)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef tuple<ll, ll, ll> Tlll;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<ll> Vl;
typedef vector<Vl> VVl;
typedef vector<VVl> VVVl;
typedef vector<Tlll> VTlll;
typedef vector<mint> Vm;
typedef vector<Vm> VVm;
typedef vector<string> Vs;
typedef vector<double> Vd;
typedef vector<char> Vc;
typedef vector<bool> Vb;
typedef vector<Pll> VPll;
typedef priority_queue<ll> PQl;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQlr;

/* inout */
ostream &operator<<(ostream &os, mint const &m) {
    os << m.val();
    return os;
}
istream &operator>>(istream &is, mint &m) {
    long long n;
    is >> n, m = n;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    int n = v.size();
    rep(i, 0, n) { os << v[i] << " \n"[i == n - 1]; }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
    int n = v.size();
    rep(i, 0, n) os << v[i];
    return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> const &p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &ma) {
    for (auto &[key, val] : ma) {
        os << key << ':' << val << '\n';
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &st) {
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++) {
        os << *itr << (i + 1 != (int)st.size() ? ' ' : '\n');
        itr++;
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, multiset<T> &st) {
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++) {
        os << *itr << (i + 1 != (int)st.size() ? ' ' : '\n');
        itr++;
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, queue<T> q) {
    while (q.size()) {
        os << q.front();
        q.pop();
        os << " \n"[q.empty()];
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, stack<T> st) {
    vector<T> v;
    while (st.size()) {
        v.push_back(st.top());
        st.pop();
    }
    reverse(ALL(v));
    os << v;
    return os;
}
template <class T, class Container, class Compare>
ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq) {
    vector<T> v;
    while (pq.size()) {
        v.push_back(pq.top());
        pq.pop();
    }
    os << v;
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &in : v) is >> in;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}

/* useful */
template <typename T>
int SMALLER(vector<T> &a, T x) {
    return lower_bound(a.begin(), a.end(), x) - a.begin();
}
template <typename T>
int orSMALLER(vector<T> &a, T x) {
    return upper_bound(a.begin(), a.end(), x) - a.begin();
}
template <typename T>
int BIGGER(vector<T> &a, T x) {
    return a.size() - orSMALLER(a, x);
}
template <typename T>
int orBIGGER(vector<T> &a, T x) {
    return a.size() - SMALLER(a, x);
}
template <typename T>
int COUNT(vector<T> &a, T x) {
    return upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
}
template <typename T, typename S>
bool chmax(T &a, S b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename S>
bool chmin(T &a, S b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void press(T &v) {
    v.erase(unique(ALL(v)), v.end());
}
template <typename T>
vector<int> zip(vector<T> a) {
    int n = a.size();
    pair<T, int> p[n];
    vector<int> v(n);
    for (int i = 0; i < n; i++) p[i] = make_pair(a[i], i);
    sort(p, p + n);
    int w = 0;
    for (int i = 0; i < n; i++) {
        if (i && p[i].first != p[i - 1].first) w++;
        v[p[i].second] = w;
    }
    return v;
}
template <typename T>
vector<T> vis(vector<T> &v) {
    vector<T> S(v.size() + 1);
    rep(i, 1, S.size()) S[i] += v[i - 1] + S[i - 1];
    return S;
}
template <typename T>
T ceil_div(T a, T b) {
    if (b < 0) a = -a, b = -b;
    return (a >= 0 ? (a + b - 1) / b : a / b);
}
template <typename T>
T floor_div(T a, T b) {
    if (b < 0) a = -a, b = -b;
    return (a >= 0 ? a / b : (a - b + 1) / b);
}
ll dtoll(double d, int g) { return round(d * pow(10, g)); }

const double EPS = 1e-10;

void init() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(12);
    cout << fixed;
}

// do {} while (next_permutation(ALL(vec)));

/********************************** START **********************************/

void sol();

int main() {
    init();
    int q = 1;
    // cin >> q;
    while (q--) sol();
    return 0;
}

/********************************** SOLVE **********************************/

template <typename T = long long>
struct CC {
    bool initialized;
    vector<T> xs;
    CC() : initialized(false) {}
    void add(T x) { xs.push_back(x); }
    void init() {
        sort(xs.begin(), xs.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
        initialized = true;
    }
    int operator()(T x) {
        if (!initialized) init();
        return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;
    }
    T operator[](int i) {
        if (!initialized) init();
        return xs[i];
    }
    int size() {
        if (!initialized) init();
        return xs.size();
    }
};

struct RMUQ {
    using S = ll;
    using F = ll;

   public:
    RMUQ() : RMUQ(0) {}
    RMUQ(int n) : RMUQ(std::vector<S>(n, e())) {}
    RMUQ(const std::vector<S> &v) : _n(int(v.size())) {
        log = ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        lz = std::vector<F>(size, id());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }
    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return e();
        l += size;
        r += size;
        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push(r >> i);
        }
        S sml = e(), smr = e();
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }
    S all_prod() { return d[1]; }
    void apply(int p, F f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = mapping(f, d[p]);
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;
        l += size;
        r += size;
        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }
        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }
        for (int i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

    S op(S a, S b) { return max(a, b); }
    S e() { return 0; }
    S mapping(F f, S x) { return f != id() ? f : x; }
    F composition(F f, F g) { return f != id() ? f : g; }
    F id() { return -2e18; }

    int ceil_pow2(int n) {
        int x = 0;
        while ((1U << x) < (unsigned int)(n)) x++;
        return x;
    }
    ll operator[](int i) { return get(i); }
    void out() {
        for (int i = 0; i < _n; i++) cout << get(i) << " \n"[i == _n - 1];
    }
    void err() {
        for (int i = 0; i < _n; i++) cerr << get(i) << " \n"[i == _n - 1];
    }

   private:
    int _n, size, log;
    std::vector<S> d;
    std::vector<F> lz;
    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
    void all_apply(int k, F f) {
        d[k] = mapping(f, d[k]);
        if (k < size) lz[k] = composition(f, lz[k]);
    }
    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};

void sol() {
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    cin >> a;
    CC<int> cc;
    rep(i, 0, n) cc.add(a[i]);
    vector<int> b = a;
    sort(ALL(b));
    RMUQ rmq(n);
    int q;
    cin >> q;
    rep(i, 2, q + 2) {
        int l, r;
        cin >> l >> r;
        // bの[l,r]ないのindexを求める
        int li = SMALLER(b, l);
        int ri = orSMALLER(b, r);
        rmq.apply(li, ri, i);
    }
    map<int, int> ma;
    rep(i, 0, n) { ma[b[i]] = rmq[i]; }
    rep(i, 0, n) cout << ma[a[i]] - 1 << endl;
}
0