結果

問題 No.1675 Strange Minimum Query
ユーザー moondrinkmoondrink
提出日時 2021-09-23 23:12:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 2,647 ms
コンパイル使用メモリ 180,064 KB
実行使用メモリ 16,500 KB
最終ジャッジ日時 2023-09-18 20:04:52
合計ジャッジ時間 14,020 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 170 ms
6,444 KB
testcase_04 AC 168 ms
9,444 KB
testcase_05 AC 45 ms
9,644 KB
testcase_06 AC 198 ms
6,692 KB
testcase_07 AC 215 ms
8,804 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 163 ms
12,244 KB
testcase_11 AC 48 ms
10,444 KB
testcase_12 AC 184 ms
13,212 KB
testcase_13 AC 288 ms
16,200 KB
testcase_14 AC 244 ms
16,296 KB
testcase_15 AC 224 ms
16,076 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 43 ms
6,220 KB
testcase_18 AC 61 ms
6,772 KB
testcase_19 AC 95 ms
13,236 KB
testcase_20 AC 168 ms
12,356 KB
testcase_21 AC 160 ms
14,292 KB
testcase_22 AC 197 ms
15,236 KB
testcase_23 AC 152 ms
7,972 KB
testcase_24 AC 142 ms
11,080 KB
testcase_25 AC 102 ms
7,168 KB
testcase_26 AC 59 ms
8,104 KB
testcase_27 AC 148 ms
15,036 KB
testcase_28 AC 83 ms
11,288 KB
testcase_29 AC 73 ms
12,816 KB
testcase_30 AC 58 ms
8,356 KB
testcase_31 AC 194 ms
9,180 KB
testcase_32 AC 255 ms
16,500 KB
testcase_33 AC 252 ms
16,288 KB
testcase_34 AC 257 ms
16,276 KB
testcase_35 AC 282 ms
16,372 KB
testcase_36 AC 285 ms
16,308 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:26:13: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   26 |   for (auto [b, l, r] : query) {
      |             ^

ソースコード

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)
    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