#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define count1 __builtin_popcount
#define all(v) v.begin(), v.end()
#define pairi pair<int, int>
#define fori(n) for(int i=0; i < n; i++)
using namespace std;
struct point{
int ma, cnt;
};
int ctoi(char x) {
return (int)x - 'a' + 1;
}
int sumab(int a, int b) {
return (a + b) * (b - a + 1) / 2;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a%b);
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
void print(auto &v) {
for (const int &i : v) cout << i << ' ';
}
constexpr int MAX = 1e+5 + 3, INF = 1e+9, MOD = 1e+9 + 7;
int temp, temp1, temp2, temp3;
vector <point> t(4*MAX);
vector <int> a, b;
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v].ma = a[tl];
t[v].cnt = (a[tl] == b[tl]);
return;
}
int tm = (tl + tr) / 2;
build(v*2, tl, tm);
build(v*2+1, tm+1, tr);
t[v].ma = max(t[v*2].ma, t[v*2+1].ma);
if (t[v*2].ma == t[v*2+1].ma) {
t[v].cnt = t[v*2].cnt + t[v*2+1].cnt;
}
else if (t[v*2].ma < t[v*2+1].ma) {
t[v].cnt = t[v*2+1].cnt;
}
else {
t[v].cnt = t[v*2].cnt;
}
}
point find(int v, int tl, int tr, int l, int r) {
if (l > r) {
point null;
null.ma = null.cnt = 0;
return null;
}
if (tl == l && tr == r) return t[v];
int tm = (tl + tr) / 2;
point res1 = find(v*2, tl, tm, l, min(r, tm));
point res2 = find(v*2+1, tm+1, tr, max(l, tm+1), r);
point res;
res.ma = max(res1.ma, res2.ma);
if (res1.ma == res2.ma) {
res.cnt = res1.cnt + res2.cnt;
}
else if (res1.ma < res2.ma) {
res.cnt = res2.cnt;
}
else {
res.cnt = res1.cnt;
}
return res;
}
void _() {
int n;
cin >> n;
vector <int> a(n), b(n);
for (int &i : a) cin >> i;
for (int &i : b) cin >> i;
int ma = *max_element(all(a));
if (ma == b[0]) {
cout << n;
return;
}
int l = 0, res=0;
for (int i=0; i < n; i++) {
if (a[i] == b[i]) {
while (i < n && a[i] <= b[i]) {
i++;
}
res += i - l;
i--;
}
else if (a[i] > b[i]) {
l = i + 1;
}
}
cout << res;
}
signed main() {
// GOOD_LUCK
srand(time(0));
int tests=1;
// cin >> tests;
while (tests--) {
_();
// cout << endl;
}
return 0;
}
// Problem X
// by Ekber_Ekber
# | 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... |