結果

問題 No.1675 Strange Minimum Query
ユーザー momoharamomohara
提出日時 2021-09-11 00:29:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,445 bytes
コンパイル時間 3,342 ms
コンパイル使用メモリ 222,656 KB
実行使用メモリ 29,596 KB
最終ジャッジ日時 2023-09-03 14:07:01
合計ジャッジ時間 10,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 214 ms
19,940 KB
testcase_04 AC 182 ms
18,332 KB
testcase_05 AC 16 ms
6,048 KB
testcase_06 AC 280 ms
19,272 KB
testcase_07 AC 290 ms
21,648 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

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) << " ";
    }
    cout << en;
}

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