結果

問題 No.1675 Strange Minimum Query
ユーザー satashunsatashun
提出日時 2021-09-11 09:44:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 4,437 bytes
コンパイル時間 2,803 ms
コンパイル使用メモリ 218,540 KB
実行使用メモリ 30,064 KB
最終ジャッジ日時 2023-09-04 18:04:36
合計ジャッジ時間 12,506 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 206 ms
14,532 KB
testcase_04 AC 188 ms
15,704 KB
testcase_05 AC 14 ms
8,276 KB
testcase_06 AC 257 ms
15,424 KB
testcase_07 AC 275 ms
17,332 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 59 ms
12,308 KB
testcase_11 AC 18 ms
8,956 KB
testcase_12 AC 66 ms
13,280 KB
testcase_13 AC 148 ms
25,816 KB
testcase_14 AC 170 ms
30,064 KB
testcase_15 AC 187 ms
28,108 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 32 ms
7,188 KB
testcase_18 AC 47 ms
7,780 KB
testcase_19 AC 62 ms
13,368 KB
testcase_20 AC 158 ms
18,124 KB
testcase_21 AC 131 ms
17,908 KB
testcase_22 AC 183 ms
21,092 KB
testcase_23 AC 145 ms
13,664 KB
testcase_24 AC 125 ms
13,944 KB
testcase_25 AC 89 ms
10,452 KB
testcase_26 AC 43 ms
9,088 KB
testcase_27 AC 118 ms
17,104 KB
testcase_28 AC 58 ms
12,244 KB
testcase_29 AC 39 ms
11,508 KB
testcase_30 AC 42 ms
8,916 KB
testcase_31 AC 186 ms
16,948 KB
testcase_32 AC 259 ms
24,772 KB
testcase_33 AC 266 ms
24,440 KB
testcase_34 AC 254 ms
24,880 KB
testcase_35 AC 208 ms
20,052 KB
testcase_36 AC 204 ms
20,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

template <class T>
V<T> make_vec(size_t a) {
    return V<T>(a);
}

template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return V<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

template <class T>
void print(T x, int suc = 1) {
    cout << x;
    if (suc == 1)
        cout << "\n";
    else if (suc == 2)
        cout << " ";
}

template <class T>
void print(const vector<T>& v, int suc = 1) {
    for (int i = 0; i < v.size(); ++i)
        print(v[i], i == int(v.size()) - 1 ? suc : 2);
}

// index of root = 1

template <class U>
struct segtree {
    using T = typename U::T;
    int sz;
    V<T> dat;

    segtree() {}
    segtree(int n) {
        sz = 1;
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, U::id());
    }

    segtree(const V<T>& a) {
        int n = a.size();
        sz = 1;
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, U::id());
        for (int i = 0; i < n; ++i) {
            dat[sz + i] = a[i];
        }
        for (int i = sz - 1; i >= 1; --i) {
            upd(i);
        }
    }

    void upd(int p) { dat[p] = U::op(dat[p << 1], dat[p << 1 | 1]); }

    void build() {
        for (int i = sz - 1; i > 0; --i) {
            dat[i] = U::op(dat[i << 1], dat[i << 1 | 1]);
        }
    }

    void modify(int p, T v) {
        p += sz;
        dat[p] = v;
        while (p >>= 1) {
            dat[p] = U::op(dat[p << 1], dat[p << 1 | 1]);
        }
    }

    //[l, r)

    T query(int l, int r) {
        T lval = U::id(), rval = U::id();
        for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
            if (l & 1) lval = U::op(lval, dat[l++]);
            if (r & 1) rval = U::op(dat[--r], rval);
        }
        return U::op(lval, rval);
    }
};

// modify only U for use

constexpr int INF = TEN(9) + 10;

struct U {
    using T = int;
    static T id() { return INF; }
    static T op(const T& a, const T& b) { return min(a, b); }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    VV<pii> ev(N + 1);
    V<tuple<int, int, int>> vec;

    rep(i, Q) {
        int l, r, x;
        cin >> l >> r >> x;
        --l;
        ev[l].eb(-1, x);
        ev[r].eb(1, x);
        vec.eb(l, r, x);
    }

    multiset<int> st;
    st.insert(1);
    V<int> A(N);
    rep(i, N) {
        sort(ALL(ev[i]));
        for (auto p : ev[i]) {
            if (p.fi == -1) {
                st.insert(p.se);
            } else {
                st.erase(st.find(p.se));
            }
        }
        A[i] = *st.rbegin();
    }

    segtree<U> seg(A);

    bool ok = 1;
    for (auto& [l, r, x] : vec) {
        if (seg.query(l, r) != x) {
            ok = 0;
        }
    }
    if (ok) {
        print(A);
    } else {
        cout << -1 << endl;
    }

    return 0;
}
0