結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー otoshigootoshigo
提出日時 2024-02-23 22:02:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 430 ms / 2,500 ms
コード長 3,382 bytes
コンパイル時間 1,293 ms
コンパイル使用メモリ 99,044 KB
実行使用メモリ 24,056 KB
最終ジャッジ日時 2024-02-23 22:03:37
合計ジャッジ時間 12,384 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 68 ms
8,392 KB
testcase_03 AC 34 ms
6,548 KB
testcase_04 AC 273 ms
18,112 KB
testcase_05 AC 193 ms
14,708 KB
testcase_06 AC 80 ms
9,004 KB
testcase_07 AC 226 ms
15,792 KB
testcase_08 AC 54 ms
7,296 KB
testcase_09 AC 403 ms
24,056 KB
testcase_10 AC 407 ms
24,056 KB
testcase_11 AC 399 ms
24,056 KB
testcase_12 AC 391 ms
24,056 KB
testcase_13 AC 428 ms
24,056 KB
testcase_14 AC 407 ms
24,056 KB
testcase_15 AC 430 ms
24,056 KB
testcase_16 AC 342 ms
24,056 KB
testcase_17 AC 345 ms
24,056 KB
testcase_18 AC 344 ms
24,056 KB
testcase_19 AC 344 ms
24,056 KB
testcase_20 AC 342 ms
24,056 KB
testcase_21 AC 345 ms
24,056 KB
testcase_22 AC 368 ms
24,056 KB
testcase_23 AC 306 ms
24,056 KB
testcase_24 AC 270 ms
24,056 KB
testcase_25 AC 270 ms
24,056 KB
testcase_26 AC 275 ms
24,056 KB
testcase_27 AC 273 ms
24,056 KB
testcase_28 AC 272 ms
24,056 KB
testcase_29 AC 272 ms
24,056 KB
testcase_30 AC 311 ms
24,056 KB
testcase_31 AC 281 ms
24,056 KB
testcase_32 AC 119 ms
10,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cassert>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

template <typename T, typename O, T (*mapping)(typename O::T, T)>
struct dual_segment_tree {
    using F = typename O::T;

public:
    explicit dual_segment_tree() {}
    explicit dual_segment_tree(int N) : dual_segment_tree(std::vector<T>(N)) {}

    explicit dual_segment_tree(const std::vector<T>& v) {
        int N = (int)v.size();
        n = N;
        size = 1;
        log = 0;
        while (size < N) {
            size <<= 1;
            log++;
        }
        data.resize(N);
        lazy.resize(size, O::e());
        for (int i = 0; i < N; i++) data[i] = v[i];
    };

    void set(int p, T x) {
        assert(0 <= p && p < n);
        push_from_root(p + size);
        data[p] = x;
    }

    T get(int p) {
        assert(0 <= p && p < n);
        push_from_root(p + size);
        return data[p];
    }

    void apply(int p, F f) {
        assert(0 <= p && p < n);
        push_from_root(p + size);
        data[p] = mapping(f, data[p]);
    }

    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);
        }
        while (l < r) {
            if (l & 1) all_apply(l++, f);
            if (r & 1) all_apply(--r, f);
            l >>= 1;
            r >>= 1;
        }
    }

private:
    int n, size, log;
    std::vector<T> data;
    std::vector<F> lazy;
    void all_apply(int k, F f) {
        if (k >= size) {
            if (k - size < n) data[k - size] = mapping(f, data[k - size]);
        } else {
            lazy[k] = O::op(f, lazy[k]);
        }
    }
    void push(int p) {
        assert(0 <= p && p < size);
        all_apply(2 * p, lazy[p]);
        all_apply(2 * p + 1, lazy[p]);
        lazy[p] = O::e();
    }
    void push_from_root(int p) {
        for (int i = log; i >= 1; i--) push(p >> i);
    }
};

using Tp=int;
const Tp ID=1<<30;

struct O{
    using T=int;
    static T op(T l,T r){return(l==ID?r:l);}
    static T e(){return ID;}
};

Tp mapping(O::T f,Tp x){return(f==ID?x:f);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,A;
    cin>>N>>A;
    vector<int>X(N);
    vector<int>V;
    for(int i=0;i<N;i++){
        cin>>X[i];
        V.push_back(X[i]);
    }
    int T;
    cin>>T;
    vector<int>L(T),R(T);
    for(int i=0;i<T;i++){
        cin>>L[i]>>R[i];
        V.push_back(L[i]);
        V.push_back(R[i]);
    }
    sort(all(V));
    V.erase(unique(all(V)),V.end());
    int l=V.size();
    map<int,int>mp;
    for(int i=0;i<l;i++)mp[V[i]]=i;
    for(int i=0;i<N;i++)X[i]=mp[X[i]];
    for(int i=0;i<T;i++){
        L[i]=mp[L[i]];
        R[i]=mp[R[i]];
    }
    dual_segment_tree<Tp,O,mapping>seg(l);
    for(int i=0;i<T;i++){
        seg.apply(L[i],R[i]+1,i+1);
    }
    for(int i=0;i<N;i++){
        int s=seg.get(X[i]);
        cout<<(s==0?-1:s)<<"\n";
    }
}
0