結果
| 問題 |
No.2220 Range Insert & Point Mex
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2023-02-17 22:28:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 137 ms / 2,000 ms |
| コード長 | 1,163 bytes |
| コンパイル時間 | 2,195 ms |
| コンパイル使用メモリ | 207,740 KB |
| 最終ジャッジ日時 | 2025-02-10 17:20:25 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct P {
bool operator<(const P &p) const {
return i != p.i ? i < p.i : abs(d) > abs(p.d);
}
int a, i, d;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<P> p;
for (int i = 0; i < n; i++) {
int l, r, a;
cin >> l >> r >> a;
l--;
if (a < n) {
p.push_back({ a, l, +1 });
p.push_back({ a, r, -1 });
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x;
cin >> x;
x--;
p.push_back({ i, x, 0 });
}
sort(p.begin(), p.end());
vector<int> r(q);
vector<int> c(n, 0);
set<int> st;
for (int i = 0; i <= n; i++) {
st.insert(i);
}
for (const auto &[a, i, d] : p) {
if (d == 0) {
r[a] = *st.begin();
} else {
if (c[a] == 0 && d == +1) st.erase(a);
if (c[a] == 1 && d == -1) st.insert(a);
c[a] += d;
}
}
for (int i = 0; i < q; i++) {
cout << r[i] << '\n';
}
return 0;
}
merom686