diff --git a/Luogu/P1503/P1503.cpp b/Luogu/P1503/P1503.cpp new file mode 100644 index 00000000..0e3dbeb7 --- /dev/null +++ b/Luogu/P1503/P1503.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int n, m, x; +char op; +std::set set; +std::stack st; + +int main() { + std::ios::sync_with_stdio(false); + cin >> n >> m; + set.insert(0); + set.insert(n + 1); + while (m--) { + cin >> op; + if (op == 'D') { + cin >> x; + set.insert(x); + st.push(x); + } else if (op == 'R') { + set.erase(st.top()); + st.pop(); + } else { + cin >> x; + auto it = set.lower_bound(x); + cout << (*it == x ? 0 : *it - *--it - 1) << endl; + } + } + return 0; +}