結果

問題 No.1675 Strange Minimum Query
ユーザー hanyuhanyu
提出日時 2021-08-21 17:19:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,064 bytes
コンパイル時間 2,581 ms
コンパイル使用メモリ 216,412 KB
実行使用メモリ 24,356 KB
最終ジャッジ日時 2023-09-02 15:11:53
合計ジャッジ時間 17,094 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 208 ms
13,632 KB
testcase_04 AC 220 ms
14,832 KB
testcase_05 WA -
testcase_06 AC 251 ms
15,052 KB
testcase_07 AC 281 ms
17,324 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 197 ms
14,444 KB
testcase_11 AC 64 ms
10,216 KB
testcase_12 AC 224 ms
15,952 KB
testcase_13 AC 338 ms
24,192 KB
testcase_14 AC 303 ms
24,088 KB
testcase_15 AC 281 ms
24,012 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 解法1
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  
  vector<vector<int>> query(q, vector<int>(3));
  for (int i = 0; i < q; i++) {
    cin >> query.at(i).at(1) >> query.at(i).at(2) >> query.at(i).at(0);
    query.at(i).at(1)--;
    query.at(i).at(2)--;
  }
  
  sort(query.rbegin(), query.rend());
  
  vector<int> a(n, 1e9);
  set<int> st, use;
  for (int i = 0; i < n; i++) st.insert(i);
  
  bool ok = true;
  for (int i = 0; i < q; i++) {
    if (i == 0 || query.at(i).at(0) != query.at(i - 1).at(0)) use.clear();
    auto it = st.lower_bound(query.at(i).at(1));
    if (it == st.end() || *it > query.at(i).at(2)) {
      auto it2 = use.lower_bound(query.at(i).at(1));
      if (it2 == use.end() || *it2 > query.at(i).at(2)) ok = false;
    }
    else {
      a.at(*it) = query.at(i).at(0);
      use.insert(*it);
      st.erase(it);
    }
  }
  
  if (ok) {
    for (int i = 0; i < n; i++) {
      if (i) cout << " ";
      cout << a.at(i);
    }
    cout << '\n';
  }
  else {
    cout << -1 << '\n';
  }
}
0