Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
using namespace std; const int INF = 2e9; int add(set
> & st, int x) { auto it = st.insert(make_pair(x, 2)).first; int res = -1; if(prev(it)->second == 1 and next(it)->second == 3) { res = next(it)->first; if(next(next(it))->first == next(it)->first + 1) { st.erase(next(next(it))); st.erase(next(it)); } else { st.insert(next(next(it)), make_pair(next(it)->first + 1, 3)); st.erase(next(it)); } st.erase(it); return res; } if(prev(it)->second == 3 and next(it)->second == 1) { res = x; st.insert(it, make_pair(res, 1)); if(next(it)->first == x + 1) { st.erase(next(it)); } else { st.insert(next(it), make_pair(x + 1, 3)); } st.erase(it); return res; } } void remove(set
> &st, int x) { auto it = st.lower_bound(make_pair(x, 2)); it = prev(it); if(it->first == x) { if(next(it)->first == x + 1) { st.erase(next(it)); st.erase(it); return; } else { st.insert(next(it), make_pair(x + 1, 1)); st.erase(it); return; } } else { st.insert(next(it), make_pair(x + 1 , 1)); st.insert(next(it), make_pair(x , 3)); } } int main() { ios_base::sync_with_stdio(false); set
> st; int n; cin >> n; st.insert(make_pair(0, 3)); st.insert(make_pair(INF, 1)); for(int i = 0; i < n; i++) { int t, code; cin >> t >> code; if(t == 1) { int res = add(st, code); cout << res << "\n"; } else { remove(st, code); } } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)