結果

問題 No.1675 Strange Minimum Query
ユーザー kzyKTkzyKT
提出日時 2021-09-10 21:34:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 2,749 bytes
コンパイル時間 2,585 ms
コンパイル使用メモリ 212,436 KB
実行使用メモリ 14,044 KB
最終ジャッジ日時 2023-09-02 16:08:11
合計ジャッジ時間 11,975 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,588 KB
testcase_01 AC 4 ms
9,480 KB
testcase_02 AC 4 ms
9,516 KB
testcase_03 AC 132 ms
13,092 KB
testcase_04 AC 118 ms
12,428 KB
testcase_05 AC 17 ms
9,508 KB
testcase_06 AC 155 ms
13,640 KB
testcase_07 AC 163 ms
13,904 KB
testcase_08 AC 5 ms
9,540 KB
testcase_09 AC 5 ms
9,528 KB
testcase_10 AC 105 ms
10,780 KB
testcase_11 AC 45 ms
9,644 KB
testcase_12 AC 117 ms
11,028 KB
testcase_13 AC 133 ms
14,044 KB
testcase_14 AC 185 ms
13,880 KB
testcase_15 AC 162 ms
13,904 KB
testcase_16 AC 4 ms
9,512 KB
testcase_17 AC 42 ms
9,852 KB
testcase_18 AC 58 ms
10,312 KB
testcase_19 AC 90 ms
10,076 KB
testcase_20 AC 164 ms
12,332 KB
testcase_21 AC 153 ms
11,640 KB
testcase_22 AC 194 ms
12,616 KB
testcase_23 AC 142 ms
12,424 KB
testcase_24 AC 136 ms
11,744 KB
testcase_25 AC 97 ms
11,028 KB
testcase_26 AC 59 ms
10,192 KB
testcase_27 AC 140 ms
11,392 KB
testcase_28 AC 78 ms
10,076 KB
testcase_29 AC 66 ms
9,552 KB
testcase_30 AC 54 ms
9,772 KB
testcase_31 AC 182 ms
13,400 KB
testcase_32 AC 255 ms
13,964 KB
testcase_33 AC 249 ms
13,828 KB
testcase_34 AC 248 ms
13,868 KB
testcase_35 AC 231 ms
13,940 KB
testcase_36 AC 234 ms
13,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

class RMQ{
public:
  int n,dat[555555];
  void init(int _n){
    n=1;
    while(n<_n)n*=2;
    fill(dat,dat+2*n-1,MAX);
  }
  void update(int k,int a){
    k+=n-1;dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b){return query(a,b,0,0,n);}
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return MAX;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
};

const int N=1<<18;
class RUQ2 {
public:
  ll d[N*2];
  void init(){mem(d);}
  void update(ll ul,ll ur,ll v){update2(ul,ur-1,v);}
  void update2(ll ul,ll ur,ll v,ll id=0,ll nl=0,ll nr=N-1){
    if(ur<nl||ul>nr)return;
    else if(ul<=nl&&ur>=nr) d[id]=v;
    else {
      if(d[id]!=-MAXL) d[2*id+1]=d[id],d[2*id+2]=d[id],d[id]=-MAXL;
      update2(ul,ur,v,2*id+1,nl,(nl+nr)/2);
      update2(ul,ur,v,2*id+2,(nl+nr)/2+1,nr);
    }
  }
  ll sum(ll sl,ll sr){return sum2(sl,sr-1);}
  ll sum2(ll sl,ll sr,ll id=0,ll nl=0,ll nr=N-1){
    if(sr<nl||sl>nr) return 0;
    else if(d[id]==-MAXL){
      ll left=sum2(sl,sr,2*id+1,nl,(nl+nr)/2);
      ll right=sum2(sl,sr,2*id+2,(nl+nr)/2+1,nr);
      return left+right;
    }
    return (min(sr,nr)-max(sl,nl)+1)*d[id];
  }
};

RMQ t;
RUQ2 t2;

void Main() {
  ll n,T;
  cin >> n >> T;
  t.init(n);
  t2.init();
  vector<PP> a(T);
  rep(i,T) cin >> a[i].S.F >> a[i].S.S >> a[i].F;
  sort(all(a));
  rep(i,T) t2.update(a[i].S.F-1,a[i].S.S,a[i].F);
  rep(i,n) t.update(i,t2.sum(i,i+1));
  rep(i,T) {
    ll d=t.query(a[i].S.F-1,a[i].S.S);
    if(d!=a[i].F) {
      pr(-1);
      return;
    }
  }
  rep(i,n) {
    if(i) cout << " ";
    ll x=min(1000000000LL,max(1LL,(ll)t.query(i,i+1)));
    cout << x;
  }
  ln;
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0