Submission #17323762
Source Code Expand
// doot diddly donger cuckerino Hahahahahah
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vi = vector<int>;
#define all(x) (x).begin(), (x).end()
const ld PI = acos(-1);
template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T, typename U>
std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) {
return stream << p.first << " " << p.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const vector<T>& vec) {
for (const T& x: vec) out << x << ' ';
return out;
}
template <typename T>
std::istream& operator>>(std::istream& in, vector<T>& vec) {
for (auto& x: vec) in >> x;
return in;
}
class MEX {
typedef std::pair<int, int> interval;
std::set<interval> s[2];
std::multiset<int> values;
void insert_pair(interval p) {
auto[x, y] = p;
if (x > y) std::swap(x, y);
s[0].insert({x, y});
s[1].insert({y, x});
}
void remove_pair(interval p) {
auto[x, y] = p;
if (x > y) std::swap(x, y);
s[0].erase({x, y});
s[1].erase({y, x});
}
std::optional<interval> is_end(int x, bool left) {
int idx = left;
auto it = s[idx].lower_bound({x, 0});
if (it != s[idx].end() && it->first == x)
return *it;
else
return std::nullopt;
}
public:
void insert(int x) {
bool ok = values.find(x) == values.end();
values.insert(x);
if (!ok) return;
auto p1 = is_end(x - 1, true);
auto p2 = is_end(x + 1, false);
if (p1 && p2) {
interval i{p1->second, p2->second};
remove_pair(*p1);
remove_pair(*p2);
insert_pair(i);
} else if (p1 && !p2) {
interval i = {p1->second, x};
remove_pair(*p1);
insert_pair(i);
} else if (!p1 && p2) {
interval i{x, p2->second};
remove_pair(*p2);
insert_pair(i);
} else if (!p1 && !p2) {
interval i{x, x};
insert_pair(i);
}
}
void remove(int x) {
values.erase(values.find(x));
if (values.find(x) != values.end()) return;
auto it = s[1].lower_bound({x, 0});
if (it->first != x && it->second != x) {
interval p1 = {it->second, x - 1};
interval p2 = {x + 1, it->first};
remove_pair(*it);
insert_pair(p1);
insert_pair(p2);
} else if (it->first != x && it->second == x) {
interval p = {x + 1, it->first};
remove_pair(*it);
insert_pair(p);
} else if (it->first == x && it->second == x) {
remove_pair(*it);
} else if (it->first == x && it->second != x) {
interval p = {it->second, x - 1};
remove_pair(*it);
insert_pair(p);
}
}
int get(int x) {
if (values.find(x) == values.end()) return x;
auto it = s[1].lower_bound({x, 0});
return it->first + 1;
}
};
class CNeqMin {
public:
void solveOne(istream& cin, ostream& cout) {
int n;
cin >> n;
MEX mex;
while (n--) {
int x;
cin >> x;
mex.insert(x);
cout << mex.get(0) << '\n';
}
}
void solve(std::istream& cin, std::ostream& cout) {
int t = 1;
for (int tc = 1; tc <= t; ++tc) {
// cout << "Case #" << tc << ": ";
solveOne(cin, cout);
}
}
};
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
CNeqMin solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Neq Min |
| User |
rds_98 |
| Language |
C++ (GCC 9.2.1) |
| Score |
300 |
| Code Size |
4057 Byte |
| Status |
AC |
| Exec Time |
334 ms |
| Memory |
17336 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
300 / 300 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
01.txt, 02.txt |
| All |
01.txt, 02.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01.txt |
AC |
9 ms |
3576 KiB |
| 02.txt |
AC |
3 ms |
3492 KiB |
| 11.txt |
AC |
268 ms |
17300 KiB |
| 12.txt |
AC |
265 ms |
17336 KiB |
| 13.txt |
AC |
334 ms |
14128 KiB |
| 14.txt |
AC |
333 ms |
14136 KiB |
| 15.txt |
AC |
118 ms |
12952 KiB |
| 16.txt |
AC |
119 ms |
12864 KiB |
| 17.txt |
AC |
122 ms |
12804 KiB |
| 18.txt |
AC |
132 ms |
12916 KiB |
| 19.txt |
AC |
84 ms |
12976 KiB |
| 20.txt |
AC |
5 ms |
3536 KiB |