제출 #895811

#제출 시각아이디문제언어결과실행 시간메모리
895811tvladm2009Exam (eJOI20_exam)C++17
12 / 100
20 ms4440 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> b[i];
    }
    vector<int> l(n + 1), r(n + 1);
    vector<int> stk;
    for (int i = 1; i <= n; ++i) {
        while (!stk.empty() && a[i] >= a[stk.back()]) {
            stk.pop_back();
        }
        if (stk.empty()) l[i] = 1;
        else l[i] = stk.back() + 1;
        stk.push_back(i);
    }
    stk.clear();
    for (int i = n; i >= 1; --i) {
        while (!stk.empty() && a[i] >= a[stk.back()]) {
            stk.pop_back();
        }
        if (stk.empty()) r[i] = n;
        else r[i] = stk.back() - 1;
        stk.push_back(i);
    }
    vector<int> mars(n + 10, 0);
    int want = b[1];
    for (int i = 1; i <= n; ++i) {
        if (a[i] == want) {
            ++mars[l[i]];
            --mars[r[i] + 1];
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        mars[i] += mars[i - 1];
        if (mars[i] > 0) {
            ++ans;
        }
    }
    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...