結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 170 ms
6,500 KB
testcase_04 AC 167 ms
9,436 KB
testcase_05 AC 44 ms
9,580 KB
testcase_06 AC 198 ms
6,872 KB
testcase_07 AC 214 ms
8,780 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 145 ms
11,952 KB
testcase_11 AC 46 ms
10,376 KB
testcase_12 AC 168 ms
13,336 KB
testcase_13 AC 283 ms
16,308 KB
testcase_14 AC 241 ms
16,104 KB
testcase_15 AC 223 ms
16,528 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 42 ms
6,204 KB
testcase_18 AC 59 ms
6,864 KB
testcase_19 AC 94 ms
13,408 KB
testcase_20 AC 166 ms
12,220 KB
testcase_21 AC 158 ms
14,376 KB
testcase_22 AC 197 ms
15,168 KB
testcase_23 AC 152 ms
8,188 KB
testcase_24 AC 140 ms
10,632 KB
testcase_25 AC 102 ms
7,196 KB
testcase_26 AC 57 ms
8,000 KB
testcase_27 AC 145 ms
15,052 KB
testcase_28 AC 82 ms
11,164 KB
testcase_29 AC 72 ms
12,808 KB
testcase_30 AC 58 ms
8,612 KB
testcase_31 AC 192 ms
9,112 KB
testcase_32 AC 253 ms
16,224 KB
testcase_33 AC 251 ms
16,532 KB
testcase_34 AC 255 ms
16,372 KB
testcase_35 AC 278 ms
16,240 KB
testcase_36 AC 280 ms
16,256 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:29:13: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   29 |   for (auto [b, l, r] : query) {
      |             ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define endl "\n" //真的裂开,遇到卡endl的,就吐了,还是\n好,endl其实是一个函数,比较慢

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,此时used已经被清空了,itr2就是used.end(),直接-1;但是如果等于的话,used没有被清空,相当于之前这个区间的最小值是B,现在又来一次还是B,根本就不影响嘛!!
      if (itr2 == used_by_b.end()) {
        cout << -1 << endl;  //不存在
        return 0;
      }
    } else {  // 如果找到了,说明还有没有访问的位置,while里面就把没有访问的位置全部置为B
      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);  //没有涉及到的下标一律设为int中的最大值,这样直接保证答案不会受影响
  for (int i = 0; i < n; i++) cout << ans[i] << " \n"[i == n - 1];
  return 0;
}
//好了,完了
0