結果

問題 No.1675 Strange Minimum Query
ユーザー tassei903tassei903
提出日時 2021-09-11 01:00:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 463 ms / 2,000 ms
コード長 2,341 bytes
コンパイル時間 4,113 ms
コンパイル使用メモリ 213,836 KB
実行使用メモリ 31,928 KB
最終ジャッジ日時 2023-09-03 15:54:03
合計ジャッジ時間 16,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 309 ms
13,112 KB
testcase_04 AC 288 ms
17,272 KB
testcase_05 AC 28 ms
11,648 KB
testcase_06 AC 378 ms
14,952 KB
testcase_07 AC 410 ms
18,028 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 145 ms
18,016 KB
testcase_11 AC 33 ms
12,756 KB
testcase_12 AC 165 ms
19,876 KB
testcase_13 AC 288 ms
26,448 KB
testcase_14 AC 338 ms
31,812 KB
testcase_15 AC 308 ms
31,928 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 60 ms
8,816 KB
testcase_18 AC 88 ms
10,420 KB
testcase_19 AC 112 ms
18,436 KB
testcase_20 AC 288 ms
21,764 KB
testcase_21 AC 249 ms
23,656 KB
testcase_22 AC 335 ms
26,996 KB
testcase_23 AC 269 ms
14,508 KB
testcase_24 AC 236 ms
18,764 KB
testcase_25 AC 176 ms
11,636 KB
testcase_26 AC 79 ms
11,520 KB
testcase_27 AC 216 ms
23,392 KB
testcase_28 AC 105 ms
15,860 KB
testcase_29 AC 68 ms
16,360 KB
testcase_30 AC 76 ms
11,820 KB
testcase_31 AC 352 ms
17,272 KB
testcase_32 AC 463 ms
30,600 KB
testcase_33 AC 459 ms
30,696 KB
testcase_34 AC 462 ms
30,328 KB
testcase_35 AC 430 ms
26,616 KB
testcase_36 AC 429 ms
26,536 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