結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー |
|
提出日時 | 2023-02-17 21:54:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 365 ms / 2,000 ms |
コード長 | 1,099 bytes |
コンパイル時間 | 2,198 ms |
コンパイル使用メモリ | 189,912 KB |
実行使用メモリ | 41,088 KB |
最終ジャッジ日時 | 2024-07-21 12:40:46 |
合計ジャッジ時間 | 9,382 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:28:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 28 | for (auto &[key, ve] : que) { | ^ main.cpp:29:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 29 | for (auto [t, v] : ve) { | ^
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; map<int, vector<pair<int, int>>> que; for (int i = 0; i < n; i++) { int l, r, v; cin >> l >> r >> v; if (v <= n) { que[l].push_back({0, v}); que[r + 1].push_back({1, v}); } } int q; cin >> q; for (int i = 0; i < q; i++) { int x; cin >> x; que[x].push_back({2, i}); } set<int> mex; for (int i = 0; i <= n; i++) { mex.insert(i); } map<int, int> cnt; vector<int> ans(q); for (auto &[key, ve] : que) { for (auto [t, v] : ve) { if (t == 0) { if (cnt[v]++ == 0) { mex.erase(v); } } else if (t == 1) { if (--cnt[v] == 0) { mex.insert(v); } } else { ans[v] = *mex.begin(); } } } for (int i = 0; i < q; i++) { cout << ans[i] << '\n'; } }