結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー ococonomy1ococonomy1
提出日時 2024-02-23 21:45:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 2,500 ms
コード長 6,211 bytes
コンパイル時間 3,203 ms
コンパイル使用メモリ 122,652 KB
実行使用メモリ 24,896 KB
最終ジャッジ日時 2024-02-23 21:46:23
合計ジャッジ時間 9,772 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 54 ms
8,832 KB
testcase_03 AC 35 ms
6,676 KB
testcase_04 AC 225 ms
15,104 KB
testcase_05 AC 163 ms
14,336 KB
testcase_06 AC 72 ms
8,832 KB
testcase_07 AC 182 ms
14,592 KB
testcase_08 AC 48 ms
6,676 KB
testcase_09 AC 309 ms
24,896 KB
testcase_10 AC 306 ms
24,896 KB
testcase_11 AC 352 ms
24,896 KB
testcase_12 AC 303 ms
24,896 KB
testcase_13 AC 308 ms
24,896 KB
testcase_14 AC 309 ms
24,896 KB
testcase_15 AC 309 ms
24,896 KB
testcase_16 AC 218 ms
24,896 KB
testcase_17 AC 215 ms
24,896 KB
testcase_18 AC 247 ms
24,896 KB
testcase_19 AC 216 ms
24,896 KB
testcase_20 AC 220 ms
24,896 KB
testcase_21 AC 217 ms
24,896 KB
testcase_22 AC 230 ms
24,896 KB
testcase_23 AC 177 ms
24,896 KB
testcase_24 AC 181 ms
24,896 KB
testcase_25 AC 175 ms
24,896 KB
testcase_26 AC 184 ms
24,896 KB
testcase_27 AC 176 ms
24,896 KB
testcase_28 AC 175 ms
24,896 KB
testcase_29 AC 175 ms
24,896 KB
testcase_30 AC 194 ms
24,896 KB
testcase_31 AC 208 ms
24,896 KB
testcase_32 AC 88 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'

template <typename T> vector<T> getvec(int n,T val){
    vector<T> ans(n);
    for(int i = 0; i < n; i++){
        cin >> ans[i];
        ans[i] += val;
    }
    return ans;
}

template <typename T> void printvec(vector<T> const& a,T val){
    int n = a.size();
    for(int i = 0; i < n; i++){
        cout << (a[i] + val);
        if(i != n - 1)cout << ' ';
    }
    cout << '\n';
}

// 区間更新ができる遅延セグ木
// 最小値の取得と、区間和の取得ができる
template <typename T> class ococo_ruq_lazy_segtree {
  public:
    int n;
    T tmax;
    // rsq:Range Sum Query
    vector<T> rsq, lazy_rsq;
    // rmq;Range Minimum Query
    vector<T> rmq, lazy_rmq;

    ococo_ruq_lazy_segtree(int N, T d) {
        syokica(N, d);
    }

    // 配列の初期化 O(N)
    //(セグ木に乗せるサイズ,型の最大値(intならIINFなど))を引数に取る
    void syokica(int a, T d) {
        n = 1;
        tmax = d;
        while(n < a) n *= 2;
        rsq.resize(2 * n - 1);
        rmq.resize(2 * n - 1);
        lazy_rsq.resize(2 * n - 1);
        lazy_rmq.resize(2 * n - 1);
        for(int i = 0; i < 2 * n - 1; i++) {
            rsq[i] = 0;
            rmq[i] = tmax;
            lazy_rsq[i] = tmax;
            lazy_rmq[i] = tmax;
        }
    }

    // k番目の点についての遅延評価 O(1)
    void lazy_evaluate(int k, int l, int r) {
        if(lazy_rsq[k] != tmax) {
            rsq[k] = lazy_rsq[k];
            if(r - l > 1) {
                lazy_rsq[2 * k + 1] = (lazy_rsq[k] / 2);
                lazy_rsq[2 * k + 2] = (lazy_rsq[k] / 2);
            }
            lazy_rsq[k] = tmax;
        }
        if(lazy_rmq[k] != tmax) {
            rmq[k] = lazy_rmq[k];
            if(r - l > 1) {
                lazy_rmq[2 * k + 1] = lazy_rmq[k];
                lazy_rmq[2 * k + 2] = lazy_rmq[k];
            }
            lazy_rmq[k] = tmax;
        }
    }

    void update_num2(int a, int b, T x, int k, int l, int r) {
        lazy_evaluate(k, l, r);
        if(b <= l || r <= a) return;

        if(a <= l && r <= b) {
            lazy_rmq[k] = x;
            lazy_rsq[k] = (T)(r - l) * x;
            lazy_evaluate(k, l, r);
        } else {
            update_num2(a, b, x, 2 * k + 1, l, (l + r) / 2);
            update_num2(a, b, x, 2 * k + 2, (l + r) / 2, r);
            // セグ木の一番子以外のノードに保持したい情報によってここの式を変える
            rmq[k] = min(rmq[2 * k + 1], rmq[2 * k + 2]);
            rsq[k] = rsq[2 * k + 1] + rsq[2 * k + 2];
        }
    }

    //[l,r)をxにする O(logN)
    void update_num(int l, int r, T x) {
        update_num2(l, r, x, 0, 0, n);
    }

    T get_sum2(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return 0;
        lazy_evaluate(k, l, r);
        if(a <= l && r <= b) return rsq[k];
        else {
            return (get_sum2(a, b, k * 2 + 1, l, (l + r) / 2) + get_sum2(a, b, k * 2 + 2, (l + r) / 2, r));
        }
    }
    //[l,r)の和の取得 O(logN)
    T get_sum(int l, int r) {
        return get_sum2(l, r, 0, 0, n);
    }

    T get_minimum2(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return tmax;
        lazy_evaluate(k, l, r);
        if(a <= l && r <= b) return rmq[k];
        else return min(get_minimum2(a, b, k * 2 + 1, l, (l + r) / 2), get_minimum2(a, b, k * 2 + 2, (l + r) / 2, r));
    }
    //[l,r)の最小値の取得 O(logN)
    T get_minimum(int l, int r) {
        return get_minimum2(l, r, 0, 0, n);
    }
};


#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //一個回答に繋がりそうな解法が見えても、実装や細かい詰めに時間がかかりそうなら別の方針を考えてみる
    //添え字回りで面倒になりそうなときは楽になる言い換えを実装の前にじっくり考える
    //ある程度考察しても全然取っ掛かりが見えないときは実験をしてみる
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    int n;
    ll a;
    cin >> n >> a;
    vector<ll> x = getvec<ll>(n,0);
    int t;
    cin >> t;
    vector<ll> l(t),r(t);
    for(int i = 0; i < t; i++){
        cin >> l[i] >> r[i];
    }
    vector<ll> temp(n + 2 * t);
    for(int i = 0; i < n; i++)temp[i] = x[i];
    for(int i = 0; i < t; i++){
        temp[i + n] = l[i];
        temp[i + n + t] = r[i];
    }
    sort(temp.begin(),temp.end());
    temp.erase(unique(temp.begin(),temp.end()),temp.end());
    const int m = temp.size();
    for(int i = 0; i < n; i++){
        x[i] = distance(temp.begin(),lower_bound(temp.begin(),temp.end(),x[i]));
    }
    for(int i = 0; i < t; i++){
        l[i] = distance(temp.begin(),lower_bound(temp.begin(),temp.end(),l[i]));
        r[i] = distance(temp.begin(),lower_bound(temp.begin(),temp.end(),r[i]));
    }

    ococo_ruq_lazy_segtree<int> ruq(m,INT_MAX);
    ruq.update_num(0,m,1);
    for(int i = 0; i < t; i++){
        ruq.update_num(l[i],r[i] + 1,(i + 1) * -1);
    }
    vector<int> ans(n,0);
    for(int i = 0; i < n; i++){
        ans[i] = ruq.get_minimum(x[i],x[i] + 1);
        ans[i] *= -1;
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << el;
    }
    return;
}

void calc(void){
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0