結果

問題 No.1675 Strange Minimum Query
ユーザー stoqstoq
提出日時 2020-05-15 18:37:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 215,336 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2023-09-02 14:58:45
合計ジャッジ時間 12,947 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 169 ms
6,412 KB
testcase_04 AC 167 ms
9,380 KB
testcase_05 AC 44 ms
9,720 KB
testcase_06 AC 197 ms
7,064 KB
testcase_07 AC 213 ms
8,820 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 156 ms
12,240 KB
testcase_11 AC 46 ms
10,520 KB
testcase_12 AC 176 ms
13,084 KB
testcase_13 AC 285 ms
16,464 KB
testcase_14 AC 244 ms
16,328 KB
testcase_15 AC 223 ms
16,512 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 43 ms
6,288 KB
testcase_18 AC 59 ms
6,696 KB
testcase_19 AC 93 ms
13,308 KB
testcase_20 AC 166 ms
12,388 KB
testcase_21 AC 157 ms
14,312 KB
testcase_22 AC 196 ms
15,296 KB
testcase_23 AC 152 ms
8,084 KB
testcase_24 AC 141 ms
10,616 KB
testcase_25 AC 102 ms
7,488 KB
testcase_26 AC 57 ms
7,980 KB
testcase_27 AC 144 ms
14,944 KB
testcase_28 AC 82 ms
11,196 KB
testcase_29 AC 72 ms
12,836 KB
testcase_30 AC 58 ms
8,288 KB
testcase_31 AC 190 ms
9,368 KB
testcase_32 AC 253 ms
16,472 KB
testcase_33 AC 251 ms
16,212 KB
testcase_34 AC 253 ms
16,496 KB
testcase_35 AC 276 ms
16,244 KB
testcase_36 AC 279 ms
16,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()

int main() {
  int n, q;
  cin >> n >> q;
  vector<array<int, 3>> query(q);
  for (int i = 0; i < q; i++) {
    int l, r, b;
    cin >> l >> r >> b;
    l--;  // 半開区間 [l, r)
    query[i] = {b, l, r};
  }
  sort(all(query));
  reverse(all(query));

  int prev = -1;
  vector<int> tmp(n);
  iota(all(tmp), 0);
  set<int> unused(all(tmp));  // 未使用の i の集合
  set<int> used_by_b;  // b_i が同じものを処理するときの i の一時保存先

  vector<int> ans(n);
  for (auto [b, l, r] : query) {
    if (b != prev) {
      prev = b;
      used_by_b.clear();
    }
    auto itr = unused.lower_bound(l);
    if (itr == unused.end() || *itr >= r) {  // 更新可能なものがない
      auto itr2 = used_by_b.lower_bound(l);
      if (itr2 == used_by_b.end() ||
          *itr2 >= r) {  // b_i が同じ他のクエリで区間内の i を使ったか
        cout << -1 << "\n";
        return 0;
      }
    } else {  // 更新可能なものがある
      while (itr != unused.end() && *itr < r) {
        ans[*itr] = b;
        used_by_b.insert(*itr);
        itr = unused.erase(itr);
      }
    }
  }

  for (auto i : unused) ans[i] = int(1e9);
  for (int i = 0; i < n; i++) cout << ans[i] << (i + 1 == n ? '\n' : ' ');
  return 0;
}
0