#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 5e5 + 7;
int a[N], p1[N], p2[N];
vector <int> add[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i)
cin >> p1[i];
for (int i = 1; i <= n; ++i) {
cin >> p2[i];
add[a[i]].app(p2[i]);
}
ii best = mp(N, N);
int b = 0;
for (int i = 1; i <= n; ++i) {
b += add[i].size();
--b;
best = min(best, mp(b, i));
}
int start = best.s + 1;
if (start == n + 1)
start = 1;
int ans = 0;
set <int> s;
for (int sh = 0; sh < n; ++sh) {
int i = start + sh;
if (i > n)
i -= n;
for (int x : add[i])
s.insert(x);
if (s.empty()) {
cout << "LMAO" << endl;
exit(1);
}
auto t = s.upper_bound(p1[i]);
if (t == s.end()) {
s.erase(s.begin());
}
else {
++ans;
s.erase(t);
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
649 ms |
43488 KB |
Output is correct |
2 |
Correct |
398 ms |
42732 KB |
Output is correct |
3 |
Correct |
516 ms |
50528 KB |
Output is correct |
4 |
Correct |
511 ms |
51168 KB |
Output is correct |
5 |
Correct |
397 ms |
29048 KB |
Output is correct |
6 |
Correct |
319 ms |
29048 KB |
Output is correct |
7 |
Correct |
425 ms |
31452 KB |
Output is correct |
8 |
Correct |
340 ms |
29688 KB |
Output is correct |
9 |
Correct |
519 ms |
32504 KB |
Output is correct |
10 |
Correct |
370 ms |
30712 KB |
Output is correct |