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;
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
typedef long long ll;
const ll MAXN = 1e5 + 5;
const ll INF = 1e9;
#define endl '\n'
#define pll pair <ll, ll>
#define fi first
#define se second
ll n;
ll a [MAXN], b [MAXN];
ll par [MAXN];
ll dp [MAXN];
int main(){
cin >> n;
ll cnt2 = 0;
for(ll i = 1; i <= n; i++){
cin >> a[i];
if(a[i-1] < a[i]) cnt2++;
}
ll cnt = 0;
for(ll i = 1; i <= n; i++){
cin >> b[i];
if(b[1] == b[i]) cnt++;
}
// if(n <= 10){
// }
if(cnt == n){
ll sblm = 0;
bool ada = false;
ll ans = 0;
a[n+1] = 2*INF;
for(ll i = 1; i <= n+1; i++){
if(a[i] == b[1]) ada = true;
if(a[i] > b[1]){
if(ada){
// cout << i << " " << sblm << endl;
ada = false;
ans += i-sblm-1;
}
sblm = i;
}
}
cout << ans << endl;
exit(0);
}
if(cnt2 == n){
vector <ll> v;
for(ll i = 1; i <= n; i++){
for(ll j = i; j <= n; j++){
if(a[j] == b[i]){
while(!v.empty() && v.back() > j){
v.pop_back();
}
v.push_back(j);
break;
}
}
}
cout << v.size() << endl;
}
}
# | 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... |