結果

問題 No.1675 Strange Minimum Query
ユーザー moondrinkmoondrink
提出日時 2021-09-24 14:37:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,978 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 181,380 KB
実行使用メモリ 16,436 KB
最終ジャッジ日時 2023-09-18 20:13:23
合計ジャッジ時間 11,761 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 171 ms
6,588 KB
testcase_04 AC 167 ms
9,364 KB
testcase_05 AC 44 ms
9,588 KB
testcase_06 AC 198 ms
7,076 KB
testcase_07 AC 212 ms
8,912 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 149 ms
11,968 KB
testcase_11 AC 46 ms
10,412 KB
testcase_12 AC 170 ms
13,148 KB
testcase_13 AC 282 ms
16,180 KB
testcase_14 AC 240 ms
16,180 KB
testcase_15 AC 224 ms
16,192 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 42 ms
6,192 KB
testcase_18 AC 58 ms
6,796 KB
testcase_19 AC 93 ms
13,316 KB
testcase_20 AC 165 ms
12,224 KB
testcase_21 AC 158 ms
14,448 KB
testcase_22 AC 195 ms
15,248 KB
testcase_23 AC 151 ms
7,996 KB
testcase_24 AC 140 ms
10,944 KB
testcase_25 AC 101 ms
7,268 KB
testcase_26 AC 57 ms
8,116 KB
testcase_27 AC 145 ms
15,196 KB
testcase_28 AC 81 ms
11,204 KB
testcase_29 AC 72 ms
12,740 KB
testcase_30 AC 57 ms
8,408 KB
testcase_31 AC 191 ms
9,112 KB
testcase_32 AC 252 ms
16,176 KB
testcase_33 AC 251 ms
16,288 KB
testcase_34 AC 253 ms
16,436 KB
testcase_35 AC 279 ms
16,176 KB
testcase_36 AC 276 ms
16,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:28:13: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   28 |   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 --;
    r --;  //由于下标是从0 - n - 1,所以l -- ,r --
    query[i] = {b, l, r};
  }
  
  sort(all(query));
  reverse(all(query));
  //把询问按照B从大到小排序

  int prev = -1;
  vector<int> tmp(n); //tmp存储位置
  for(int i = 0;i < n;i ++ ) tmp[i] = i;
  set<int> unused(all(tmp));  // 未使用的位置集合
  set<int> used_by_b;  // 已经使用的位置集合

  vector<int> ans(n); //答案
  for (auto [b, l, r] : query) {
    if (b != prev) {        //如果当前最小值不等于上一次的最小值,对于再次访问到之前访问过的区间,肯定就不存在,就必须要把unused清空,这样就找不到了,就输出-1
      prev = b;
      used_by_b.clear();
    }
    auto itr = unused.lower_bound(l);  //看还有没有没被访问过的位置,并且是在l-r里面的
    if (itr == unused.end() || *itr > r) {  // 如果当前询问的区间所有的点之前都访问过,并且赋了答案
      auto itr2 = used_by_b.lower_bound(l);  //如果当前B小于上一次的B,此时unused已经被清空了,i
      if (itr2 == used_by_b.end()) {         // 如果找不到或者找到的不在l-r范围里面
        cout << -1 << "\n";  //不存在
        return 0;
      }
    } else {  // 如果找到了
      while (itr != unused.end() && *itr <= r) {
        ans[*itr] = b;   //当前位置对应的值为最小值B
        used_by_b.insert(*itr);  //记录当前itr已经使用过了  
        itr = unused.erase(itr);  //把itr从未使用过中的set中删除
      }
    }
  }

  for (auto i : unused) ans[i] = int(1e9);  //没有涉及到的下标一律设为int中的最大值
  for (int i = 0; i < n; i++) cout << ans[i] << (i + 1 == n ? '\n' : ' ');
  return 0;
}
0