結果

問題 No.1675 Strange Minimum Query
ユーザー outlineoutline
提出日時 2021-09-10 22:05:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 4,359 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 152,744 KB
実行使用メモリ 9,712 KB
最終ジャッジ日時 2023-09-02 17:47:38
合計ジャッジ時間 13,189 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 211 ms
5,380 KB
testcase_04 AC 208 ms
6,752 KB
testcase_05 AC 18 ms
5,100 KB
testcase_06 AC 248 ms
5,848 KB
testcase_07 AC 286 ms
7,472 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 105 ms
8,016 KB
testcase_11 AC 30 ms
7,272 KB
testcase_12 AC 116 ms
8,148 KB
testcase_13 AC 163 ms
9,316 KB
testcase_14 AC 256 ms
9,512 KB
testcase_15 AC 197 ms
9,520 KB
testcase_16 AC 1 ms
4,372 KB
testcase_17 AC 52 ms
4,372 KB
testcase_18 AC 77 ms
4,644 KB
testcase_19 AC 111 ms
7,468 KB
testcase_20 AC 260 ms
8,564 KB
testcase_21 AC 228 ms
8,308 KB
testcase_22 AC 314 ms
8,868 KB
testcase_23 AC 226 ms
5,640 KB
testcase_24 AC 210 ms
6,420 KB
testcase_25 AC 145 ms
5,256 KB
testcase_26 AC 72 ms
5,432 KB
testcase_27 AC 200 ms
8,004 KB
testcase_28 AC 103 ms
7,544 KB
testcase_29 AC 67 ms
7,220 KB
testcase_30 AC 70 ms
5,356 KB
testcase_31 AC 296 ms
7,212 KB
testcase_32 AC 408 ms
9,332 KB
testcase_33 AC 412 ms
9,712 KB
testcase_34 AC 405 ms
9,456 KB
testcase_35 AC 319 ms
9,400 KB
testcase_36 AC 318 ms
9,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<typename Monoid, typename OperatorMonoid = Monoid>
struct LazySegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;
    using G = function<Monoid(Monoid, OperatorMonoid)>;
    using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;

    int sz;
    vector<Monoid> data;
    vector<OperatorMonoid> lazy;
    const F f;
    const G g;
    const H h;
    const Monoid M1;            // モノイドの単位元
    const OperatorMonoid OM0;   // 作用素モノイドの単位元

    LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &M1, const OperatorMonoid OM0)
        : f(f), g(g), h(h), M1(M1), OM0(OM0)
    {
        sz = 1;
        while(sz < n)   sz <<= 1;
        data.assign(sz << 1, M1);
        lazy.assign(sz << 1, OM0);
    }

    void set(int k, const Monoid &x){
        data[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            data[k] = f(data[k << 1], data[k << 1 | 1]);
        }
    }

    void propagate(int k){
        if(lazy[k] != OM0){
            if(k < sz){
                lazy[k << 1] = h(lazy[k << 1], lazy[k]);
                lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
            }
            data[k] = g(data[k], lazy[k]);
            lazy[k] = OM0;
        }
    }

    Monoid update(int a, int b, const OperatorMonoid &x, int k = 1, int l = 0, int r = -1){
        if(r == -1)     r = sz;
        propagate(k);
        if(r <= a || b <= l)    return data[k];
        else if(a <= l && r <= b){
            lazy[k] = h(lazy[k], x);
            propagate(k);
            return data[k];
        }
        else{
            return data[k] = f(update(a, b, x, k << 1, l, (l + r) >> 1),
                                update(a, b, x, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    Monoid query(int a, int b, int k = 1, int l = 0, int r = -1){
        if(r == -1)     r = sz;
        propagate(k);
        if(r <= a || b <= l)    return M1;
        else if(a <= l && r <= b)   return data[k];
        else{
            return f(query(a, b, k << 1, l, (l + r) >> 1),
                        query(a, b, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    Monoid operator[](const int &i){
        int k = 1, l = 0, r = sz, m;
        while(k < sz){
            propagate(k);
            k <<= 1;
            m = (l + r) >> 1;
            if(i + 1 <= m)  r = m;
            else { l = m; ++k; }
        }
        propagate(k);
        return data[k];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, Q;
    cin >> N >> Q;
    vector<tuple<int, int, int>> dat(Q);
    for(auto& [B, L, R] : dat){
        cin >> L >> R >> B;
        --L;
    }
    sort(begin(dat), end(dat));

    auto op = [](int l, int r){return min(l, r);};
    auto mapping = [](int l, int r){return r;};
    auto composition = [](int l, int r){return r;};
    LazySegmentTree<int, int> seg(N, op, mapping, composition, 1000000000, 0);
    for(auto& [b, l, r] : dat)  seg.update(l, r, b);
    
    for(auto& [b, l, r] : dat){
        if(seg.query(l, r) != b)    return puts("-1") & 0;
    }

    for(int i = 0; i < N; ++i){
        cout << seg[i] << (i == N - 1 ? '\n' : ' ');
    }

    return 0;
}
0