#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 5e5 + 5;
vector<int> v[N];
int a[N], b[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v[a[i] - 1].push_back(x);
}
int need = 0;
for (int i = 0; i < n; i++) {
need += v[i].size();
need = max(0, need - 1);
}
set<int> st;
for (int i = 0; i < need; i++) {
for (int j : v[i])
st.insert(j);
}
int ans = 0;
for (int i = need; i < n; i++) {
for (int j : v[i])
st.insert(j);
if (*st.rbegin() > b[i]) {
st.erase(st.lower_bound(b[i]));
ans++;
}
else {
st.erase(st.begin());
}
}
for (int i = 0; i < need; i++) {
for (int j : v[i])
st.insert(j);
if (*st.rbegin() > b[i]) {
st.erase(st.lower_bound(b[i]));
ans++;
}
else {
st.erase(st.begin());
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
798 ms |
44264 KB |
Output is correct |
2 |
Correct |
506 ms |
42968 KB |
Output is correct |
3 |
Correct |
664 ms |
50692 KB |
Output is correct |
4 |
Correct |
613 ms |
51100 KB |
Output is correct |
5 |
Incorrect |
417 ms |
30856 KB |
Output isn't correct |
6 |
Correct |
349 ms |
30416 KB |
Output is correct |
7 |
Incorrect |
553 ms |
34424 KB |
Output isn't correct |
8 |
Incorrect |
397 ms |
32760 KB |
Output isn't correct |
9 |
Incorrect |
487 ms |
35576 KB |
Output isn't correct |
10 |
Incorrect |
421 ms |
31992 KB |
Output isn't correct |