結果

問題 No.1675 Strange Minimum Query
ユーザー tassei903tassei903
提出日時 2021-09-11 00:59:47
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 2,341 bytes
コンパイル時間 18,144 ms
コンパイル使用メモリ 136,576 KB
実行使用メモリ 32,020 KB
最終ジャッジ日時 2023-09-03 15:53:34
合計ジャッジ時間 20,183 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 296 ms
13,156 KB
testcase_04 AC 271 ms
18,024 KB
testcase_05 AC 26 ms
11,716 KB
testcase_06 AC 367 ms
14,748 KB
testcase_07 AC 392 ms
17,880 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 151 ms
18,196 KB
testcase_11 AC 33 ms
12,504 KB
testcase_12 AC 165 ms
20,036 KB
testcase_13 AC 316 ms
26,612 KB
testcase_14 AC 375 ms
31,964 KB
testcase_15 AC 343 ms
32,020 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 62 ms
9,012 KB
testcase_18 AC 93 ms
10,256 KB
testcase_19 AC 119 ms
18,548 KB
testcase_20 AC 305 ms
21,968 KB
testcase_21 AC 267 ms
23,692 KB
testcase_22 AC 354 ms
27,664 KB
testcase_23 AC 285 ms
15,236 KB
testcase_24 AC 251 ms
18,848 KB
testcase_25 AC 181 ms
11,648 KB
testcase_26 AC 84 ms
11,628 KB
testcase_27 AC 230 ms
23,464 KB
testcase_28 AC 114 ms
16,072 KB
testcase_29 AC 70 ms
16,364 KB
testcase_30 AC 79 ms
11,732 KB
testcase_31 AC 371 ms
17,372 KB
testcase_32 AC 485 ms
30,936 KB
testcase_33 AC 486 ms
30,740 KB
testcase_34 AC 485 ms
30,828 KB
testcase_35 AC 449 ms
26,884 KB
testcase_36 AC 445 ms
26,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1<<25;
using ll =  long long;
using vi = vector<int>;
using pi = pair<int,int>;
using vvi = vector<vector<int>>;

template <typename T>
struct RMQ {
    const T INF = numeric_limits<T>::max();
    int n;         // 葉の数
    vector<T> dat; // 完全二分木の配列
    RMQ(int n_) : n(), dat(n_ * 4, INF) { // 葉の数は 2^x の形
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
    void update(int i, T x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // the minimum element of [a,b)
    T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return INF;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

int main() {
  int n, q;cin >> n >> q;
  vvi ar1(n), ar2(n);
  vector<tuple<int,int,int>> que;
  rep(i, q) {
    int l,r,b;cin >> l >> r >> b;
    l--;r--;
    que.emplace_back(make_tuple(l,r,b));
    ar1[l].emplace_back(b);
    ar2[r].emplace_back(b);
  }
  multiset<int> ms;
  vi res(n, -1);
  rep(i, n) {
    for (int j : ar1[i]) {
      //cout << j << endl;
      ms.insert(j);
    }
    if(ms.size()==0)res[i] = 1;
    else res[i] = *ms.rbegin();
    //cout <<" "<< ms.size() << endl;
    for (int j : ar2[i]) {
      //cout << j << *ms.find(j) << endl;
      //if (ms.find(j)==ms.end())cout << "%" << endl;
      ms.erase(ms.find(j));
      //cout << "#" << endl;
    }
  }
/*   rep(i, n) {
    cout << res[i] << " ";
  }
  cout << endl; */
  RMQ<int> rmq(n);
  rep(i, n) {
    rmq.update(i, res[i]);
  }
  int ans = 1;
  rep(i, q) {
    int l,r,b;tie(l,r,b) = que[i];
    if (rmq.query(l, r+1) > b) {
      ans = 0;
      break;
    } 
  }
  if(ans) {
    rep(i, n){
      cout << res[i];
      if (i<n-1)cout << " ";
    }
    cout << endl;
  }
  else {
    cout << -1 << endl;
  }
}
0