#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mxN = 2e6 + 1;
const int mod = 1e9 + 7;
int a[mxN],b[mxN];
bool tk[mxN];
int main()
{
ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
int n;
cin >>n;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
for(int i = 0;i < n;i++) cin >>a[i];
for(int i = 0;i < n;i++) {
cin >>b[i];
q.push({b[i],i});
}
int bf = 0;
int l = n,r = n;
int diff = 0;
int ans = 0;
while(q.size()){
pair<int,int> u = q.top();
// cout<<u.first<<' '<<u.second<<'\n';
q.pop();
if(u.first != bf && bf){
for(int i = l;i <= r;i++){
ans -= tk[i];
tk[i] = 0;
if(b[i] == bf){
ans++;
tk[i] = 1;
}
}
// cout<<l<<' '<<r<<' '<<ans<<'\n';
l = n;r = n;
diff = 0;
}
int num = 0;
int mx = 0;
for(int i = u.second;i < n;i++){
mx = max(mx,a[i]);
num += (b[i] == u.first);
num -= tk[i];
if(mx == u.first){
if(num >= diff){
r = i;
l = u.second;
diff = num;
}
}
}
for(int i = u.second;i >= 0;i--){
mx = max(mx,a[i]);
num += (b[i] == u.first);
num -= tk[i];
if(mx == u.first){
if(num >= diff){
r = u.second;
l = i;
diff = num;
}
}
}
bf = u.first;
}
for(int i = l;i <= r;i++){
ans -= tk[i];
tk[i] = 0;
if(b[i] == bf){
ans++;
tk[i] = 1;
}
}
// cout<<l<<' '<<r<<' '<<ans<<'\n';
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
52 ms |
584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |