結果

問題 No.1675 Strange Minimum Query
ユーザー momoharamomohara
提出日時 2021-09-11 00:33:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 4,451 bytes
コンパイル時間 2,653 ms
コンパイル使用メモリ 223,288 KB
実行使用メモリ 28,656 KB
最終ジャッジ日時 2023-09-03 14:20:39
合計ジャッジ時間 12,207 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 204 ms
18,948 KB
testcase_04 AC 174 ms
18,992 KB
testcase_05 AC 16 ms
6,024 KB
testcase_06 AC 240 ms
19,432 KB
testcase_07 AC 272 ms
20,924 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 65 ms
11,352 KB
testcase_11 AC 24 ms
7,824 KB
testcase_12 AC 71 ms
11,996 KB
testcase_13 AC 168 ms
27,712 KB
testcase_14 AC 180 ms
27,824 KB
testcase_15 AC 193 ms
28,656 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 32 ms
6,096 KB
testcase_18 AC 48 ms
7,400 KB
testcase_19 AC 64 ms
10,204 KB
testcase_20 AC 147 ms
17,148 KB
testcase_21 AC 129 ms
15,368 KB
testcase_22 AC 170 ms
19,348 KB
testcase_23 AC 147 ms
17,616 KB
testcase_24 AC 123 ms
13,708 KB
testcase_25 AC 100 ms
10,980 KB
testcase_26 AC 44 ms
7,964 KB
testcase_27 AC 118 ms
14,100 KB
testcase_28 AC 59 ms
10,396 KB
testcase_29 AC 41 ms
8,716 KB
testcase_30 AC 42 ms
7,408 KB
testcase_31 AC 196 ms
23,224 KB
testcase_32 AC 236 ms
22,796 KB
testcase_33 AC 230 ms
23,216 KB
testcase_34 AC 240 ms
23,872 KB
testcase_35 AC 196 ms
19,384 KB
testcase_36 AC 193 ms
18,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

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

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, int _rev, ll _cap) : to(_to), rev(_rev), cap(_cap) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, (int)G[to].size(), cap));
    if(revFlag)
        G[to].push_back(Edge(from, (int)G[from].size() - 1, revCap));
}

template <typename T, typename F, typename U>
class SegmentTree {
  private:
    T e;
    F op;
    U st;
    ll n;
    vector<T> dat;

  public:
    SegmentTree(F f, U u, T _e, vector<T> v) : op(f), st(u), e(_e) {
        int _n = v.size();
        n = 1;
        while(n < _n)
            n *= 2;
        dat.resize(2 * n - 1, e);
        REP(i, _n)
        dat[n + i - 1] = v[i];
        for(int i = n - 2; i >= 0; i--)
            dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
    SegmentTree(F f, U u, T _e, int _n) : op(f), st(u), e(_e) {
        n = 1;
        while(n < _n)
            n *= 2;
        dat.resize(2 * n - 1, e);
        for(int i = n - 2; i >= 0; i--)
            dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
    void update(int i, T x) {
        i += n - 1;
        dat[i] = st(dat[i], x);
        while(i > 0) {
            i = (i - 1) / 2;
            dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    T get(int i) {
        i += n - 1;
        return dat[i];
    }
    T query(int l, int r) {
        //[l,r)でのクエリ処理
        T left = e, right = e;
        l += n - 1;
        r += n - 1;
        while(l < r) {
            if((l & 1) == 0)
                left = op(left, dat[l]);
            if((r & 1) == 0)
                right = op(dat[r - 1], right);
            l = l / 2;
            r = (r - 1) / 2;
        }
        return op(left, right);
    }
};

void solve() {
    ll n, q;
    cin >> n >> q;

    vec<P> ls, rs;
    vec<tp> lrb;
    REP(i, q) {
        ll l, r, b;
        cin >> l >> r >> b;
        l--;
        lrb.push_back({l, r, b});
        ls.push_back({l, b});
        rs.push_back({r, b});
    }

    sort(all(ls));
    sort(all(rs));
    ll pr = 0;
    ll pl = 0;

    using S = ll;
    S id = INF;
    auto op = [](S a, S b) { return min(a, b); };
    auto st = [](S a, S b) { return min(a, b); };
    SegmentTree seg(op, st, id, n);

    multiset<ll> set;

    REP(i, n) {
        while(pr < q) {
            auto [r, b] = rs[pr];
            if(r != i)
                break;
            auto it = set.find(b);
            set.erase(it);
            pr++;
        }
        while(pl < q) {
            auto [l, b] = ls[pl];
            if(l != i)
                break;
            set.insert(b);
            pl++;
        }
        if(set.size()) {
            auto it = --set.end();
            ll x = *it;
            seg.update(i, x);
        } else {
            seg.update(i, 1e9);
        }
    }

    REP(i, q) {
        auto [l, r, b] = lrb[i];
        if(seg.query(l, r) != b) {
            cout << -1 << en;
            return;
        }
    }

    REP(i, n) {
        cout << seg.get(i) << (i == n - 1 ? "\n" : " ");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(10);

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}
0