結果

問題 No.1675 Strange Minimum Query
ユーザー tnakao0123tnakao0123
提出日時 2021-09-11 21:25:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,140 bytes
コンパイル時間 3,166 ms
コンパイル使用メモリ 101,648 KB
実行使用メモリ 8,688 KB
最終ジャッジ日時 2023-09-05 10:36:02
合計ジャッジ時間 10,359 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,716 KB
testcase_01 AC 4 ms
7,492 KB
testcase_02 AC 3 ms
7,628 KB
testcase_03 AC 16 ms
7,932 KB
testcase_04 AC 49 ms
7,684 KB
testcase_05 AC 16 ms
7,552 KB
testcase_06 AC 18 ms
8,408 KB
testcase_07 AC 31 ms
8,604 KB
testcase_08 AC 3 ms
7,560 KB
testcase_09 AC 4 ms
7,608 KB
testcase_10 AC 90 ms
7,780 KB
testcase_11 AC 28 ms
7,636 KB
testcase_12 AC 100 ms
8,096 KB
testcase_13 AC 119 ms
8,572 KB
testcase_14 AC 187 ms
8,580 KB
testcase_15 AC 144 ms
8,436 KB
testcase_16 AC 4 ms
7,844 KB
testcase_17 AC 45 ms
7,616 KB
testcase_18 AC 66 ms
7,668 KB
testcase_19 AC 86 ms
8,192 KB
testcase_20 AC 200 ms
7,784 KB
testcase_21 AC 175 ms
8,504 KB
testcase_22 AC 236 ms
8,580 KB
testcase_23 WA -
testcase_24 AC 166 ms
7,620 KB
testcase_25 WA -
testcase_26 AC 59 ms
7,612 KB
testcase_27 AC 158 ms
8,400 KB
testcase_28 AC 78 ms
7,972 KB
testcase_29 AC 55 ms
8,148 KB
testcase_30 AC 57 ms
7,672 KB
testcase_31 WA -
testcase_32 AC 319 ms
8,520 KB
testcase_33 AC 322 ms
8,460 KB
testcase_34 AC 319 ms
8,360 KB
testcase_35 AC 252 ms
8,444 KB
testcase_36 AC 252 ms
8,688 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 < n; i++) qs[i].read();
  sort(qs, qs + qn);

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

  for (int i = 0; i < n; 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 (st.min_range(qs[i].l, qs[i].r) != 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