You are viewing a single comment's thread. Return to all comments →
long long stack[100005],max[100005],x; long long N,top=-1; long long q; scanf("%lld",&N);
for( long long i=0;i<N;i++ ) { scanf("%lld",&q); switch(q) { case 1: scanf(" %lld",&x); top++; if(max[top-1]<x) { max[top]=x; } else max[top]=max[top-1]; stack[top]=x; break; case 2: top--; break; case 3: printf("%lld\n",max[top]); break; } }
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 →
long long stack[100005],max[100005],x; long long N,top=-1; long long q; scanf("%lld",&N);