You are viewing a single comment's thread. Return to all comments →
Solution using C++, the slowest time is 0.02s
int main() { std::stack<int> st; int n, x; scanf("%d", &n); for (int i = 0; i < n; i++) { int q; scanf("%d", &q); switch (q) { case 1: scanf("%d", &x); if (st.empty()) { st.push(x); } else { st.push(max(x, st.top())); } break; case 2: if (!st.empty()) { st.pop(); } break; case 3: printf("%d\n", st.top()); break; default: break; } } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
Solution using C++, the slowest time is 0.02s