結果

問題 No.1675 Strange Minimum Query
ユーザー moondrinkmoondrink
提出日時 2021-09-23 23:08:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,462 bytes
コンパイル時間 3,128 ms
コンパイル使用メモリ 180,040 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2023-09-18 20:04:18
合計ジャッジ時間 13,143 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 173 ms
6,768 KB
testcase_04 AC 167 ms
9,448 KB
testcase_05 AC 44 ms
9,620 KB
testcase_06 AC 197 ms
7,008 KB
testcase_07 AC 214 ms
8,972 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 146 ms
11,948 KB
testcase_11 AC 46 ms
10,452 KB
testcase_12 AC 177 ms
13,076 KB
testcase_13 AC 286 ms
16,348 KB
testcase_14 AC 245 ms
16,304 KB
testcase_15 AC 224 ms
16,364 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 43 ms
6,156 KB
testcase_18 AC 59 ms
6,852 KB
testcase_19 AC 93 ms
13,468 KB
testcase_20 AC 165 ms
12,532 KB
testcase_21 AC 156 ms
14,520 KB
testcase_22 AC 197 ms
15,172 KB
testcase_23 AC 152 ms
8,088 KB
testcase_24 AC 140 ms
11,028 KB
testcase_25 AC 103 ms
7,396 KB
testcase_26 AC 57 ms
8,056 KB
testcase_27 AC 146 ms
15,036 KB
testcase_28 AC 82 ms
11,204 KB
testcase_29 AC 72 ms
12,744 KB
testcase_30 AC 58 ms
8,568 KB
testcase_31 AC 191 ms
9,180 KB
testcase_32 AC 253 ms
16,180 KB
testcase_33 AC 255 ms
16,176 KB
testcase_34 AC 253 ms
16,300 KB
testcase_35 AC 275 ms
16,512 KB
testcase_36 AC 277 ms
16,188 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;
    query[i] = {b, l, r};
  }
  sort(all(query));
  reverse(all(query));

  int prev = -1;
  vector<int> tmp(n + 1);
  iota(all(tmp), 1);
  set<int> unused(all(tmp));  // 未使用の i の集合
  set<int> used_by_b;  // b_i が同じものを処理するときの i の一時保存先
  //for(int i = 0;i < tmp.size();i ++ ) cout << tmp[i] << endl;
  //for(auto x : unused) cout << x << endl;
  //cout << used_by_b.size() << endl;
  vector<int> ans(n + 1);
  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 = 1; i <= n; i++) cout << ans[i] << (i == n ? '\n' : ' ');
  return 0;
}
0