結果
| 問題 |
No.1675 Strange Minimum Query
|
| コンテスト | |
| ユーザー |
moondrink
|
| 提出日時 | 2021-09-24 14:39:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 301 ms / 2,000 ms |
| コード長 | 1,988 bytes |
| コンパイル時間 | 1,854 ms |
| コンパイル使用メモリ | 183,536 KB |
| 実行使用メモリ | 16,640 KB |
| 最終ジャッジ日時 | 2024-07-05 09:42:59 |
| 合計ジャッジ時間 | 11,895 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:29:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
29 | for (auto [b, l, r] : query) {
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define endl "\n"
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 << endl; //不存在
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] << " \n"[i == n - 1];
return 0;
}
moondrink