求助,只ac 2个点,为什么用数组代替stl栈就ac了
查看原帖
求助,只ac 2个点,为什么用数组代替stl栈就ac了
967480
jiunichenyin楼主2024/5/3 16:01
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm> 
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<map>
#define maxn 2500100
using namespace std;
long long n,ans=0;
stack<long long>q;
bool you[maxn];
int main() {
    cin >> n;
    long long k, h;
    for (int i = 1; i <= n; ++i) {
        cin >> k >> h;
        ans++;
        while (!q.empty()) {
            if (q.top() > h) {
                q.pop();
            }
            if (q.top() == h) {
                ans--;
                break;
            }
            if (q.top() < h) {
                break;
            }
        }
        q.push(h);
    }
    cout << ans;
    return 0;
}
inline int read() {
    int w = 1, q = 0;
    char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') q = q * 10 + ch - '0', ch = getchar();
    return w * q;
}
2024/5/3 16:01
加载中...