結果

問題 No.1675 Strange Minimum Query
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-16 19:27:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 399 ms / 2,000 ms
コード長 3,640 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 127,476 KB
実行使用メモリ 16,236 KB
最終ジャッジ日時 2024-06-10 01:30:17
合計ジャッジ時間 12,379 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 249 ms
8,140 KB
testcase_04 AC 230 ms
10,588 KB
testcase_05 AC 20 ms
8,320 KB
testcase_06 AC 281 ms
8,992 KB
testcase_07 AC 309 ms
12,028 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 155 ms
13,140 KB
testcase_11 AC 44 ms
12,452 KB
testcase_12 AC 164 ms
13,392 KB
testcase_13 AC 256 ms
16,056 KB
testcase_14 AC 332 ms
16,164 KB
testcase_15 AC 268 ms
16,108 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 58 ms
6,940 KB
testcase_18 AC 90 ms
6,940 KB
testcase_19 AC 126 ms
12,772 KB
testcase_20 AC 264 ms
14,500 KB
testcase_21 AC 232 ms
13,900 KB
testcase_22 AC 303 ms
14,900 KB
testcase_23 AC 242 ms
8,620 KB
testcase_24 AC 212 ms
9,812 KB
testcase_25 AC 155 ms
7,504 KB
testcase_26 AC 75 ms
8,140 KB
testcase_27 AC 200 ms
13,392 KB
testcase_28 AC 103 ms
12,620 KB
testcase_29 AC 73 ms
12,788 KB
testcase_30 AC 74 ms
8,064 KB
testcase_31 AC 309 ms
11,452 KB
testcase_32 AC 393 ms
16,228 KB
testcase_33 AC 399 ms
16,196 KB
testcase_34 AC 392 ms
16,100 KB
testcase_35 AC 367 ms
16,236 KB
testcase_36 AC 360 ms
16,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

//https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_H

using namespace std;

template<class S, S (*op)(S, S), S (*e)(),
         class F, S (*mapping)(F, S), F (*composition)(F, F), F (*id)()>struct LazySegTree {
    vector<S> seg;
    vector<F> lazy;
    long long N = 1;

    LazySegTree (long long n) : LazySegTree(vector<S>(n, e())) {}
    LazySegTree (const vector<S> &v){
        long long n = v.size();
        while (N < n) N *= 2;
        seg.resize(N*2-1, e());
        lazy.resize(N*2-1, id());
        for (long long i=0; i<n; i++) seg[i+N-1] = v[i];
        for (long long i=N-2; i>=0; i--){
            seg[i] = op(seg[i*2+1], seg[i*2+2]);
        }
    }

    void eval (long long idx, long long bitl, long long bitr){
        if (lazy[idx] != id()){
            seg[idx] = mapping(lazy[idx], seg[idx]);
            if (bitl != bitr){
                lazy[2*idx+1] = composition(lazy[idx], lazy[2*idx+1]);
                lazy[2*idx+2] = composition(lazy[idx], lazy[2*idx+2]);
            }
            lazy[idx] = id();
        }
    }

    //a[i] -> f(a[i]) for l<=i<=r
    void set (long long l, long long r, F val){
        _set(l, r, val, 0, 0, N-1);
    }

    void _set (long long l, long long r, F val, long long idx, long long bitl, long long bitr){
        eval(idx, bitl, bitr);

        if (r < bitl || l > bitr) return;
        if (l <= bitl && bitr <= r){
            lazy[idx] = composition(lazy[idx], val);
            eval(idx, bitl, bitr);
        }
        else{
            long long bitm = (bitl+bitr)/2;
            _set(l, r, val, idx*2+1, bitl, bitm);
            _set(l, r, val, idx*2+2, bitm+1, bitr);
            seg[idx] = op(seg[idx*2+1], seg[idx*2+2]);
        }
    }

    //op(a[l], ..., a[r])
    S prod (long long l, long long r) {
        return _prod(l, r, 0, 0, N-1);
    }

    S all_prod() const{
        return seg[0];
    }

    S _prod (long long l, long long r, long long idx, long long bitl, long long bitr) {
        if (r < bitl || l > bitr) return e();
        eval(idx, bitl, bitr);
        if (l <= bitl && bitr <= r) return seg[idx];
        long long bitm = (bitl+bitr)/2;
        return op(_prod(l, r, idx*2+1, bitl, bitm), _prod(l, r, idx*2+2, bitm+1, bitr));
    }

    S get (long long i) {
        return prod(i, i);
    }

    void show() const{
        for (int i=0; i<N*2-1; i++) cout << seg[i] << " ";
        for (int i=0; i<N*2-1; i++) cout << lazy[i] << " ";
    }
};

using S = long long;
using F = long long;
F ID = -1; S INF = 1e9;
S op(S a, S b){return min(a, b);}
S e() {return INF;}
S mapping(F f, S x){
    if (f == ID) return x;
    else return f;
}
F composition(F f, F g){
    if (f == ID) return g;
    else return f;
}
F id() {return ID;}

int main(){

    long long N, Q, b, l, r;
    cin >> N >> Q;
    LazySegTree<S, op, e, F, mapping, composition, id> tree(N);
    vector<tuple<long long, long long, long long>> BLR(Q);
    for (int i=0; i<Q; i++){
        cin >> l >> r >> b;
        l--; r--;
        BLR[i] = {b, l, r};
    }
    sort(BLR.begin(), BLR.end());

    for (int i=0; i<Q; i++){
        tie(b, l, r) = BLR[i];
        tree.set(l, r, b);
    }

    for (int i=0; i<Q; i++){
        tie(b, l, r) = BLR[i];
        if (tree.prod(l, r) != b){
            cout << -1 << endl;
            return 0;
        }
    }

    for (int i=0; i<N-1; i++) cout << tree.get(i) << " ";
    cout << tree.get(N-1) << endl;

    return 0;
}
0