結果

問題 No.1675 Strange Minimum Query
ユーザー Hideaki ItoHideaki Ito
提出日時 2021-09-11 20:45:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,669 bytes
コンパイル時間 5,232 ms
コンパイル使用メモリ 215,556 KB
実行使用メモリ 22,776 KB
最終ジャッジ日時 2023-09-05 09:43:40
合計ジャッジ時間 12,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 113 ms
12,852 KB
testcase_04 AC 153 ms
13,048 KB
testcase_05 AC 19 ms
5,212 KB
testcase_06 AC 133 ms
13,396 KB
testcase_07 AC 168 ms
16,536 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 65 ms
8,180 KB
testcase_11 AC 24 ms
5,908 KB
testcase_12 AC 72 ms
8,440 KB
testcase_13 AC 176 ms
22,776 KB
testcase_14 AC 205 ms
22,352 KB
testcase_15 AC 215 ms
21,184 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 34 ms
5,504 KB
testcase_18 AC 49 ms
6,344 KB
testcase_19 AC 66 ms
8,088 KB
testcase_20 AC 154 ms
13,144 KB
testcase_21 AC 135 ms
11,800 KB
testcase_22 AC 182 ms
13,932 KB
testcase_23 WA -
testcase_24 AC 129 ms
10,648 KB
testcase_25 WA -
testcase_26 AC 45 ms
6,444 KB
testcase_27 AC 122 ms
10,916 KB
testcase_28 AC 61 ms
7,880 KB
testcase_29 AC 44 ms
6,864 KB
testcase_30 AC 43 ms
6,244 KB
testcase_31 WA -
testcase_32 AC 248 ms
17,864 KB
testcase_33 AC 244 ms
17,456 KB
testcase_34 AC 252 ms
17,488 KB
testcase_35 AC 201 ms
13,932 KB
testcase_36 AC 202 ms
13,684 KB
権限があれば一括ダウンロードができます

ソースコード

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];
    if(i != n-1) cout << ' ';
  }
  cout << endk;
  return 0;
}
0