Submission #588418

#TimeUsernameProblemLanguageResultExecution timeMemory
588418dozerExam (eJOI20_exam)C++14
12 / 100
24 ms5476 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sp " " #define endl "\n" #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define N 500005 #define pii pair<int, int> #define st first #define nd second #define modulo 1000000007 #define LOGN 18 #define int long long int nxt[N], prv[N], a[N], b[N]; int32_t main() { fastio(); int n; cin>>n; for (int i = 1; i <= n; i++) cin>>a[i]; for (int i = 1; i <= n; i++) cin>>b[i]; prv[1] = 0; a[0] = modulo; nxt[n] = n + 1; a[n + 1] = modulo; for (int i = 2; i <= n; i++) { prv[i] = i - 1; while(a[prv[i]] < a[i]) prv[i] = prv[prv[i]]; } for (int i = n - 1; i >= 1; i--) { nxt[i] = i + 1; while (a[nxt[i]] < a[i]) nxt[i] = nxt[nxt[i]]; } int ans = 0; for (int i = 1; i <= n; i++) { if (a[i] != b[i]) continue; int l = prv[i], r = nxt[i]; if (a[nxt[i]] == a[i]) r = i + 1; ans += r - l - 1; //cout<<l<<sp<<r<<endl; } cout<<ans<<endl; cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#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...