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;
int n, i, j, l, r;
int a[100005];
int b[100005];
int c[100005];
int v[100005];
int seg[400020];
bool lazy[400020];
int dp[5005];
void Update(int from, int to, int start=0, int ende=n-1, int indx=1) {
if (lazy[indx]) return;
if (from == start && to == ende) {
seg[indx] = to-from+1;
lazy[indx] = true;
return;
}
int mid = (start+ende)/2;
if (to <= mid) Update(from, to, start, mid, 2*indx);
else if (from > mid) Update(from, to, mid+1, ende, 2*indx+1);
else {
Update(from, mid, start, mid, 2*indx);
Update(mid+1, to, mid+1, ende, 2*indx+1);
}
seg[indx] = seg[2*indx]+seg[2*indx+1];
}
int main() {
scanf("%d", &n);
for (i=0; i < n; ++i) scanf("%d", &a[i]);
for (i=0; i < n; ++i) scanf("%d", &b[i]);
for (i=0; i < n; ++i) {
if (a[i] == b[0]) {
for (l=i; l-1 >= 0 && a[l-1]<a[i]; --l);
for (r=i; r+1 < n && a[r+1]<a[i]; ++r);
Update(l, r);
}
}
printf("%d\n", seg[1]);
return 0;
}
Compilation message (stderr)
exam.cpp: In function 'int main()':
exam.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
exam.cpp:33:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | for (i=0; i < n; ++i) scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
exam.cpp:34:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | for (i=0; i < n; ++i) scanf("%d", &b[i]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |