結果

問題 No.1675 Strange Minimum Query
ユーザー 👑 emthrmemthrm
提出日時 2021-09-10 21:28:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 2,561 bytes
コンパイル時間 3,415 ms
コンパイル使用メモリ 217,808 KB
実行使用メモリ 26,092 KB
最終ジャッジ日時 2023-09-02 15:56:52
合計ジャッジ時間 11,004 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 73 ms
7,464 KB
testcase_04 AC 85 ms
12,352 KB
testcase_05 AC 51 ms
12,812 KB
testcase_06 AC 86 ms
8,024 KB
testcase_07 AC 102 ms
11,444 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 139 ms
23,376 KB
testcase_11 AC 71 ms
20,812 KB
testcase_12 AC 162 ms
26,092 KB
testcase_13 AC 150 ms
22,596 KB
testcase_14 AC 163 ms
23,392 KB
testcase_15 AC 160 ms
22,668 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 31 ms
7,800 KB
testcase_18 AC 39 ms
8,404 KB
testcase_19 AC 100 ms
19,700 KB
testcase_20 AC 104 ms
17,708 KB
testcase_21 AC 123 ms
21,348 KB
testcase_22 AC 141 ms
22,648 KB
testcase_23 AC 73 ms
10,464 KB
testcase_24 AC 91 ms
15,220 KB
testcase_25 AC 54 ms
9,388 KB
testcase_26 AC 48 ms
10,464 KB
testcase_27 AC 124 ms
22,052 KB
testcase_28 AC 80 ms
15,712 KB
testcase_29 AC 89 ms
18,380 KB
testcase_30 AC 51 ms
10,984 KB
testcase_31 AC 91 ms
12,228 KB
testcase_32 AC 165 ms
24,116 KB
testcase_33 AC 161 ms
24,400 KB
testcase_34 AC 163 ms
24,164 KB
testcase_35 AC 189 ms
24,240 KB
testcase_36 AC 185 ms
23,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Band>
struct SparseTable {
  using Fn = std::function<Band(Band, Band)>;

  SparseTable() {}

  SparseTable(const std::vector<Band> &a, Fn fn) { init(a, fn); }

  void init(const std::vector<Band> &a, Fn fn_) {
    is_built = true;
    fn = fn_;
    int n = a.size(), table_h = 0;
    lg.assign(n + 1, 0);
    for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
    while ((1 << table_h) <= n) ++table_h;
    dat.assign(table_h, std::vector<Band>(n));
    for (int j = 0; j < n; ++j) dat[0][j] = a[j];
    for (int i = 1; i < table_h; ++i) for (int j = 0; j + (1 << i) <= n; ++j) {
      dat[i][j] = fn(dat[i - 1][j], dat[i - 1][j + (1 << (i - 1))]);
    }
  }

  Band query(int left, int right) const {
    assert(is_built && left < right);
    int h = lg[right - left];
    return fn(dat[h][left], dat[h][right - (1 << h)]);
  }

private:
  bool is_built = false;
  Fn fn;
  std::vector<int> lg;
  std::vector<std::vector<Band>> dat;
};

int main() {
  int n, q; cin >> n >> q;
  vector<int> l(q), r(q), b(q); REP(i, q) cin >> l[i] >> r[i] >> b[i], --l[i], --r[i];
  vector<int> ord(q);
  iota(ALL(ord), 0);
  sort(ALL(ord), [&](int l, int r) -> bool { return b[l] > b[r]; });
  vector<int> a(n, 1);
  set<int> s;
  REP(i, n) s.emplace(i);
  for (int i : ord) {
    for (auto it = s.lower_bound(l[i]); it != s.end() && *it <= r[i]; it = s.erase(it)) {
      a[*it] = b[i];
    }
  }
  SparseTable<int> sparse_table(a, [](int a, int b) -> int { return min(a, b); });
  REP(i, q) {
    if (sparse_table.query(l[i], r[i] + 1) != b[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  REP(i, n) cout << a[i] << " \n"[i + 1 == n];
  return 0;
}
0