結果

問題 No.1675 Strange Minimum Query
ユーザー tko919tko919
提出日時 2021-09-11 01:13:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 2,464 bytes
コンパイル時間 2,412 ms
コンパイル使用メモリ 210,436 KB
実行使用メモリ 9,616 KB
最終ジャッジ日時 2023-09-03 16:28:01
合計ジャッジ時間 13,912 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 213 ms
5,496 KB
testcase_04 AC 192 ms
6,676 KB
testcase_05 AC 17 ms
5,072 KB
testcase_06 AC 254 ms
6,048 KB
testcase_07 AC 270 ms
7,596 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 136 ms
8,044 KB
testcase_11 AC 39 ms
7,268 KB
testcase_12 AC 154 ms
7,988 KB
testcase_13 AC 336 ms
9,412 KB
testcase_14 AC 319 ms
9,384 KB
testcase_15 AC 337 ms
9,564 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 52 ms
4,388 KB
testcase_18 AC 74 ms
4,484 KB
testcase_19 AC 104 ms
7,460 KB
testcase_20 AC 232 ms
8,448 KB
testcase_21 AC 203 ms
8,180 KB
testcase_22 AC 266 ms
8,824 KB
testcase_23 AC 214 ms
5,548 KB
testcase_24 AC 189 ms
6,476 KB
testcase_25 AC 141 ms
5,172 KB
testcase_26 AC 68 ms
5,512 KB
testcase_27 AC 181 ms
7,996 KB
testcase_28 AC 95 ms
7,616 KB
testcase_29 AC 69 ms
7,212 KB
testcase_30 AC 67 ms
5,356 KB
testcase_31 AC 278 ms
7,460 KB
testcase_32 AC 355 ms
9,616 KB
testcase_33 AC 359 ms
9,472 KB
testcase_34 AC 357 ms
9,456 KB
testcase_35 AC 343 ms
9,460 KB
testcase_36 AC 345 ms
9,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

template<typename M,typename N
   ,M (*f)(M,M),M (*g)(M,N),N (*h)(N,N)>
class LazySegmentTree{
   int sz,height; vector<M> data; vector<N> lazy;
   const M m1; const N n1;
   M ref(int k){return g(data[k],lazy[k]);}
   void recalc(int k){while(k>>=1)data[k]=f(ref(2*k),ref(2*k+1));}
   void thrust(int k){for(int i=height;i>0;i--)eval(k>>i);}
   void eval(int k){
      lazy[2*k]=h(lazy[2*k],lazy[k]); lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
      data[k]=ref(k); lazy[k]=n1;
   }
public:
   LazySegmentTree(int n,const M &m1,const N n1):m1(m1),n1(n1){
      sz=1,height=0; while(sz<n)sz<<=1,height++;
      data.assign(2*sz,m1); lazy.assign(2*sz,n1);
   }
   void run(vector<M>& v){
      rep(i,0,v.size())data[i+sz]=v[i];
      for(int k=sz-1;k>0;k--)data[k]=f(data[2*k],data[2*k+1]);
   }
   void set(int a,M x){thrust(a+=sz); data[a]=x; recalc(a);}
   void update(int a,int b,N x){
      if(a>=b)return;
      thrust(a+=sz); thrust(b+=sz-1);
      for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
         if(l&1)lazy[l]=h(lazy[l],x),++l;
         if(r&1)--r,lazy[r]=h(lazy[r],x);
      }
      recalc(a); recalc(b);
   }
   M query(int a,int b){
      if(a>=b)return m1;
      thrust(a+=sz); thrust(b+=sz-1);
      M L=m1,R=m1;
      for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
         if(l&1)L=f(L,ref(l++));
         if(r&1)R=f(ref(--r),R);
      } return f(L,R);
   }
};

int f(int a,int b){return min(a,b);}
int g(int a,int b){return (b==inf?a:b);}
int h(int a,int b){return (b==inf?a:b);}

int main(){
   int n,q;
   cin>>n>>q;
   LazySegmentTree<int,int,f,g,h> seg(n,inf,inf);
   using T=array<int,3>;
   vector<T> a(q);
   rep(i,0,q){
      cin>>a[i][1]>>a[i][2]>>a[i][0];
      a[i][1]--;
   }
   sort(ALL(a));
   for(auto& xyz:a){
      seg.update(xyz[1],xyz[2],xyz[0]);
   }
   for(auto& xyz:a){
      if(seg.query(xyz[1],xyz[2])!=xyz[0]){
         puts("-1");
         return 0;
      }
   }
   rep(i,0,n){
      int ret=seg.query(i,i+1);
      chmin(ret,1000000000);
      cout<<ret<<(i==n-1?'\n':' ');
   }
   return 0;
}
0