Submission #467765

#TimeUsernameProblemLanguageResultExecution timeMemory
467765LumosExam (eJOI20_exam)C++17
12 / 100
141 ms10808 KiB
//amira #include <bits/stdc++.h> using namespace std; #define endl "\n" #define f first #define s second #define pb push_back #define pii pair<int,int> #define ll long long #define pll pair <ll,ll> #define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int M = 1e9+7; const int N = 2e5 + 111; const ll INF = 1e10 + 1; const int K = 205; ll n,a[N],b[N],l[N],r[N],p[N]; map <ll,ll> cnt; int main() { #ifdef MM freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt[a[i]]++; } stack <ll> st; for (int i = n; i >= 1; i--) { while (!st.empty() && a[st.top()] <= a[i]) { st.pop(); } if (st.empty()) r[i] = n + 1; else r[i] = st.top(); st.push(i); } while (!st.empty()) st.pop(); for (int i = 1; i <= n; i++) { while (!st.empty() && a[st.top()] <= a[i]) { st.pop(); } if (st.empty()) l[i] = 0; else l[i] = st.top(); st.push(i); } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n; i++) { if (a[i] == b[1]) { p[l[i] + 1]++; p[r[i]]--; } } for (int i = 1; i <= n; i++) p[i] += p[i - 1]; ll cnt = 0; for (int i = 1; i <= n; i++) if (p[i]) cnt++; cout << cnt; 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...