結果

問題 No.1675 Strange Minimum Query
ユーザー だれだれ
提出日時 2021-09-10 21:45:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 5,152 bytes
コンパイル時間 3,852 ms
コンパイル使用メモリ 192,704 KB
実行使用メモリ 17,732 KB
最終ジャッジ日時 2023-09-02 16:40:46
合計ジャッジ時間 12,867 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 129 ms
7,100 KB
testcase_04 AC 120 ms
9,704 KB
testcase_05 AC 12 ms
5,956 KB
testcase_06 AC 151 ms
6,892 KB
testcase_07 AC 175 ms
9,052 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 72 ms
14,692 KB
testcase_11 AC 24 ms
11,064 KB
testcase_12 AC 78 ms
15,376 KB
testcase_13 AC 116 ms
17,732 KB
testcase_14 AC 170 ms
16,700 KB
testcase_15 AC 152 ms
17,196 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 37 ms
6,460 KB
testcase_18 AC 54 ms
6,588 KB
testcase_19 AC 79 ms
14,148 KB
testcase_20 AC 172 ms
13,128 KB
testcase_21 AC 156 ms
15,224 KB
testcase_22 AC 208 ms
15,028 KB
testcase_23 AC 150 ms
8,608 KB
testcase_24 AC 139 ms
10,220 KB
testcase_25 AC 102 ms
7,056 KB
testcase_26 AC 51 ms
8,716 KB
testcase_27 AC 136 ms
15,236 KB
testcase_28 AC 70 ms
12,320 KB
testcase_29 AC 50 ms
13,748 KB
testcase_30 AC 49 ms
8,712 KB
testcase_31 AC 204 ms
10,488 KB
testcase_32 AC 277 ms
15,600 KB
testcase_33 AC 282 ms
16,096 KB
testcase_34 AC 272 ms
15,656 KB
testcase_35 AC 243 ms
16,776 KB
testcase_36 AC 234 ms
16,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_set>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}

template<class T, T (*op)(T, T), T (*e)(), class U, T (*mapping)(T, U), U (*composition)(U, U), U (*id)()>
struct LazySegTree{
private:
    int n;
    int log = 0;
    vector<T> data;
    vector<U> lazy;

    inline T eval_at(int x){
        return mapping(data[x], lazy[x]);
    }

    inline void propagate_at(int x){
        if (lazy[x] == id()) return;
        data[x] = eval_at(x);
        if (x < n){
            lazy[x << 1] = composition(lazy[x << 1], lazy[x]);
            lazy[(x << 1) | 1] = composition(lazy[(x << 1) | 1], lazy[x]);
        }
        lazy[x] = id();
        return;
    }

    void propagate_down(int x){
        for (int i = log; i >= 1; i--){
            if (x >> i & 1){
                for (int j = i; j >= 0; j--){
                    propagate_at(x >> j);
                }
                return;
            }
        }
    }

    inline void merge_up(int x){
        while (x > 1){
            x >>= 1;
            data[x] = op(eval_at(x << 1), eval_at((x << 1) | 1));
        }
    }

public:
    LazySegTree(int n) : LazySegTree(vector<T>(n, e())) {}
    LazySegTree(vector<T> v){
        while (1 << log < int(v.size())){
            log++;
        }
        n = 1 << log;
        data.resize(n << 1, e());
        lazy.resize(n << 1, id());
        for (int i = 0; i < int(v.size()); i++){
            data[i + n] = v[i];
        }
        for (int i = n - 1; i >= 1; i--){
            data[i] = op(data[i << 1], data[(i << 1) | 1]);
        }
    }

    void set(int x, T value){
        x += n;
        propagate_down(x);
        data[x] = value;
        lazy[x] = id();
        merge_up(x);
    }

    T get(int x){
        propagate_down(x + n);
        return eval_at(x + n);
    }

    void apply(int l, int r, U value){
        l += n;
        r += n;

        int lx = l / (l & -l);
        int rx = r / (r & -r) - 1;

        propagate_down(lx);
        propagate_down(rx);

        while (l < r){
            if (l & 1){
                lazy[l] = composition(lazy[l], value);
                l++;
            }
            if (r & 1){
                r--;
                lazy[r] = composition(lazy[r], value);
            }
            l >>= 1;
            r >>= 1;
        }

        merge_up(lx);
        merge_up(rx);
    }

    T prod(int l, int r){
        l += n;
        r += n;

        propagate_down(l / (l & -l));
        propagate_down(r / (r & -r) - 1);

        T lx = e(), rx = e();

        while (l < r){
            if (l & 1){
                lx = op(lx, eval_at(l));
                l++;
            }
            if (r & 1){
                r--;
                rx = op(eval_at(r), rx);
            }
            l >>= 1;
            r >>= 1;
        }

        return op(lx, rx);
    }

    T all_prod(){
        return eval_at(1);
    }
};

int op(int a, int b){
    return min(a, b);
}

int e(){
    return 1e9;
}

int mapping(int a, int b){
    if (b == -1) return a;
    return max(a, b);
}

int composition(int a, int b){
    if (b == -1) return a;
    return max(a, b);
}

int id(){
    return -1;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<int> a(n, 1);
    LazySegTree<int, op, e, int, mapping, composition, id> seg(a);
    vector<tuple<int, int, int>> v;
    while (q--){
        int l, r, b;
        cin >> l >> r >> b;
        l--;
        seg.apply(l, r, b);
        v.emplace_back(l, r, b);
    }
    for (auto [l, r, b]: v){
        if (seg.prod(l, r) != b){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> ans(n, 1);
    rep(i, n) ans[i] = seg.get(i);
    cout << ans << endl;
}
0