結果

問題 No.1675 Strange Minimum Query
ユーザー Hideaki ItoHideaki Ito
提出日時 2021-09-11 20:37:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,636 bytes
コンパイル時間 3,295 ms
コンパイル使用メモリ 217,252 KB
実行使用メモリ 23,336 KB
最終ジャッジ日時 2023-09-05 09:31:12
合計ジャッジ時間 10,372 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 116 ms
12,880 KB
testcase_04 AC 151 ms
13,568 KB
testcase_05 AC 19 ms
5,108 KB
testcase_06 AC 136 ms
13,524 KB
testcase_07 AC 172 ms
15,396 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;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  int _n;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : _n(n), f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int p, const Monoid &x) {
    assert(0 <= p && p < _n);
    seg[p + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int p, const Monoid &x) {
    assert(0 <= p && p < _n);
    p += sz;
    seg[p] = x;
    while(p >>= 1) {
      seg[p] = f(seg[2 * p + 0], seg[2 * p + 1]);
    }
  }

  Monoid query(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    Monoid L = M1, R = M1;
    for(l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
      if(l & 1) L = f(L, seg[l++]);
      if(r & 1) R = f(seg[--r], R);
    }
    return f(L, R);
  }

  Monoid get(const int &p) const {
    assert(0 <= p && p < _n);
    return seg[p + sz];
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  multiset<int> st;
  vector<tuple<int, int, int>> in;
  vector<tuple<int, int, int>> A;
  rep(i, q) {
    int l, r, b;
    cin >> l >> r >> b;
    l--;
    in.push_back({l, r, b});
    A.push_back({l, 1, b});
    A.push_back({r, -1, b});
  }
  sort(all(A));
  vector<int> mn(n, 1000000000);
  int l = 0;
  rep(i, n) {
    while(l < 2*n && get<0>(A[l]) == i) {
      auto [p, t, b] = A[l];
      if(t == -1) {
        assert(st.find(b) != st.end());
        st.erase(st.find(b));
      } else {
        st.insert(b);
      }
      l++;
    }
    if(st.empty()) continue;
    mn[i] = *(--st.end());
  }
  SegmentTree<int> seg(n, [](int a, int b) { return min(a, b); }, INT_MAX);
  rep(i, n) seg.update(i, mn[i]);
  for(auto [l, r, b]: in) {
    if(seg.query(l, r) > b) {
      cout << -1 << endk;
      return 0;
    }
  }
  rep(i, n) cout << mn[i] << ' ';
  cout << endk;
  return 0;
}
0