TLE求调
查看原帖
TLE求调
1409685
zhaoyikuan_kkk楼主2024/8/26 14:40

前三个AC,后三个TLE,求大佬帮忙调试!

#include <bits/stdc++.h>
using namespace std;
long long maxn(stack<long long> t)
{
    int n = 0;
    while(!t.empty())
    {
        if(n < t.top())
        {
            n = t.top();
        }
        t.pop();
    }
    return n;
}
int main()
{
    stack<long long> t;
    int n, v, b, a[200001], xb = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> v;
        if(v == 0)
        {
            cin >> b;
            t.push(b);
        }
        if(v == 1)
        {
            t.pop();
        }
        if(v == 2)
        {
            a[xb] = maxn(t);
            xb++;
        }
    }
    for(int i = 0; i < xb; i++)
    {
        cout << a[i]<<endl;
    }
    return 0;
}
2024/8/26 14:40
加载中...