# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103987 | manhlinh1501 | Exam (eJOI20_exam) | C++17 | 18 ms | 4432 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 1e5 + 5;
#define left ___left
#define right ___right
int N;
int a[MAXN];
int b[MAXN];
namespace subtask2 {
bool is_subtask() {
for(int i = 1; i < N; i++) {
if(b[i] != b[i + 1]) return false;
}
return true;
}
int left[MAXN];
int right[MAXN];
int cnt[MAXN];
void solution() {
if(is_subtask() == false) return;
for(int i = 1; i <= N; i++) {
left[i] = i - 1;
while(left[i] > 0 and a[left[i]] <= a[i])
left[i] = left[left[i]];
}
for(int i = N; i >= 1; i--) {
right[i] = i + 1;
while(right[i] <= N and a[right[i]] <= a[i])
right[i] = right[right[i]];
}
for(int i = 1; i <= N; i++) {
left[i]++;
right[i]--;
}
for(int i = 1; i <= N; i++) {
if(a[i] == b[i]) {
cnt[left[i]]++;
cnt[right[i] + 1]--;
}
}
for(int i = 1; i <= N; i++) cnt[i] += cnt[i - 1];
int ans = 0;
for(int i = 1; i <= N; i++) ans += (cnt[i] > 0);
cout << ans;
exit(0);
}
}
signed main() {
#define task ""
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i];
for(int i = 1; i <= N; i++) cin >> b[i];
subtask2::solution();
return (0 ^ 0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |