結果

問題 No.1675 Strange Minimum Query
ユーザー 👑 Nachia
提出日時 2021-09-10 21:53:55
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 4,822 ms
コンパイル使用メモリ 133,480 KB
最終ジャッジ日時 2025-01-24 10:20:15
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/segtree>
#include <atcoder/lazysegtree>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)


namespace RQ{
  using S = int;
  S e(){ return 1000000000; };
  S op(S l, S r){ return 1000000000; };
  using F = int;
  S mapping(F f, S x){ if(f == -1) return x; return f; }
  F composition(F f, F x){ if(f == -1) return x; return f; }
  F id(){ return -1; }
  using RQ = atcoder::lazy_segtree<S,op,e,F,mapping,composition,id>;
}
namespace RMQ{
  using S = int;
  S e(){ return 1000000000; };
  S op(S l, S r){ return min(l,r); };
  using RQ = atcoder::segtree<S,op,e>;
}


struct Query{ int l,r,q; };


int main(){
  int N,Q; cin >> N >> Q;
  vector<Query> queries(Q);
  for(auto& a : queries){ cin >> a.l >> a.r >> a.q; a.l--; }
  sort(queries.begin(), queries.end(), [](Query l, Query r)->bool{ return l.q < r.q; });

  RQ::RQ rq(N);
  for(auto a : queries) rq.apply(a.l, a.r, a.q);
  vector<int> A(N);
  rep(i,N) A[i] = rq.get(i);
  RMQ::RQ rmq(A);
  bool ok = true;
  for(auto a : queries) if(rmq.prod(a.l, a.r) != a.q) ok = false;

  if(!ok){ cout << "-1\n"; return 0; }

  rep(i,N){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << "\n";
  return 0;
}




struct ios_do_not_sync {
    ios_do_not_sync() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0