結果

問題 No.1675 Strange Minimum Query
ユーザー Hideaki ItoHideaki Ito
提出日時 2021-09-11 20:42:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,670 bytes
コンパイル時間 5,239 ms
コンパイル使用メモリ 216,264 KB
実行使用メモリ 22,796 KB
最終ジャッジ日時 2023-09-05 09:39:46
合計ジャッジ時間 12,007 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 114 ms
13,216 KB
testcase_04 AC 141 ms
14,228 KB
testcase_05 AC 18 ms
5,212 KB
testcase_06 AC 131 ms
13,540 KB
testcase_07 AC 165 ms
16,216 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 65 ms
8,244 KB
testcase_11 AC 24 ms
5,800 KB
testcase_12 AC 73 ms
8,580 KB
testcase_13 AC 177 ms
22,796 KB
testcase_14 AC 201 ms
22,460 KB
testcase_15 AC 214 ms
20,332 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 34 ms
5,528 KB
testcase_18 AC 49 ms
6,488 KB
testcase_19 AC 66 ms
8,216 KB
testcase_20 AC 155 ms
13,256 KB
testcase_21 AC 136 ms
11,948 KB
testcase_22 AC 183 ms
14,120 KB
testcase_23 WA -
testcase_24 AC 128 ms
10,880 KB
testcase_25 WA -
testcase_26 AC 46 ms
6,256 KB
testcase_27 AC 119 ms
11,220 KB
testcase_28 AC 61 ms
7,920 KB
testcase_29 AC 43 ms
6,776 KB
testcase_30 AC 43 ms
6,320 KB
testcase_31 WA -
testcase_32 AC 246 ms
18,308 KB
testcase_33 AC 240 ms
17,512 KB
testcase_34 AC 250 ms
17,916 KB
testcase_35 AC 203 ms
14,208 KB
testcase_36 AC 202 ms
12,952 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