結果

問題 No.1675 Strange Minimum Query
ユーザー tnakao0123tnakao0123
提出日時 2021-09-11 21:32:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 3,113 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 101,848 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-09-05 10:49:41
合計ジャッジ時間 10,775 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,580 KB
testcase_01 AC 4 ms
7,496 KB
testcase_02 AC 3 ms
7,560 KB
testcase_03 AC 130 ms
8,008 KB
testcase_04 AC 116 ms
7,680 KB
testcase_05 AC 12 ms
7,568 KB
testcase_06 AC 154 ms
8,324 KB
testcase_07 AC 164 ms
8,408 KB
testcase_08 AC 4 ms
7,676 KB
testcase_09 AC 4 ms
7,644 KB
testcase_10 AC 75 ms
7,664 KB
testcase_11 AC 22 ms
7,564 KB
testcase_12 AC 83 ms
7,628 KB
testcase_13 AC 109 ms
8,468 KB
testcase_14 AC 156 ms
8,440 KB
testcase_15 AC 126 ms
8,508 KB
testcase_16 AC 3 ms
7,556 KB
testcase_17 AC 36 ms
7,692 KB
testcase_18 AC 54 ms
7,616 KB
testcase_19 AC 65 ms
7,764 KB
testcase_20 AC 158 ms
7,628 KB
testcase_21 AC 138 ms
7,552 KB
testcase_22 AC 185 ms
7,724 KB
testcase_23 AC 148 ms
7,692 KB
testcase_24 AC 133 ms
7,596 KB
testcase_25 AC 98 ms
7,588 KB
testcase_26 AC 46 ms
7,548 KB
testcase_27 AC 122 ms
7,628 KB
testcase_28 AC 61 ms
7,720 KB
testcase_29 AC 41 ms
7,672 KB
testcase_30 AC 46 ms
7,564 KB
testcase_31 AC 196 ms
8,168 KB
testcase_32 AC 249 ms
8,388 KB
testcase_33 AC 249 ms
8,416 KB
testcase_34 AC 249 ms
8,704 KB
testcase_35 AC 207 ms
8,444 KB
testcase_36 AC 209 ms
8,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1675.cc:  No.1675 Strange Minimum Query - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_E2 = 1 << 19; // = 524288
const int MAX_QN = 200000;
const int MAX_A = 1000000000;

/* typedef */

template <typename T, const int MAX_E2>
struct SegTreeMinDelay {
  int n, e2;
  T nodes[MAX_E2], minf;
  bool dls[MAX_E2];
  SegTreeMinDelay() {}

  void init(int _n, T _minf) {
    n = _n; minf = _minf;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(nodes, nodes + MAX_E2, minf);
    //fill(dls, dls + MAX_E2, false);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { geti(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = min(nodes[j * 2 + 1], nodes[j * 2 + 2]);
  }

  void __update(int k) {
    if (dls[k]) {
      int k0 = k * 2 + 1, k1 = k0 + 1;
      nodes[k0] = nodes[k1] = nodes[k];
      dls[k0] = dls[k1] = true;
      dls[k] = false;
    }
  }

  void updateall() {
    for (int j = 0; j < e2 - 1; j++) __update(j);
  }
   
  void set_range(int r0, int r1, T v, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k] = v;
      dls[k] = true;
      return;
    }

    __update(k);

    int im = (i0 + i1) / 2;
    int k0 = k * 2 + 1, k1 = k0 + 1;
    set_range(r0, r1, v, k0, i0, im);
    set_range(r0, r1, v, k1, im, i1);
    nodes[k] = min(nodes[k0], nodes[k1]);
  }
  void set_range(int r0, int r1, T v) { set_range(r0, r1, v, 0, 0, e2); }

  T min_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return minf;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    __update(k);

    int im = (i0 + i1) / 2;
    T v0 = min_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = min_range(r0, r1, k * 2 + 2, im, i1);
    return min(v0, v1);
  }
  T min_range(int r0, int r1) { return min_range(r0, r1, 0, 0, e2); }
};

struct Query {
  int l, r, b;
  Query() {}
  Query(int _l, int _r, int _b): l(_l), r(_r), b(_b) {}

  void read() { scanf("%d%d%d", &l, &r, &b); l--; }

  bool operator<(const Query &q) const { return b < q.b; }
};

/* global variables */

Query qs[MAX_QN];
SegTreeMinDelay<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);

  for (int i = 0; i < qn; i++) qs[i].read();
  sort(qs, qs + qn);

  st.init(n, qs[qn - 1].b);

  for (int i = 0; i < qn; i++)
    st.set_range(qs[i].l, qs[i].r, qs[i].b);
  st.updateall();

  for (int i = 0; i < qn; i++) {
    int v = st.min_range(qs[i].l, qs[i].r);
    //printf("(%d,%d)=%d <-> %d\n", qs[i].l, qs[i].r, v, qs[i].b);
    if (v != qs[i].b) {
      puts("-1"); return 0;
    }
  }

  for (int i = 0; i < n; i++)
    printf("%d%c", st.geti(i), (i + 1 < n) ? ' ' : '\n');
  return 0;
}
0