10039 | 2024-03-25 18:15:03 | 111 | Növekvő Ödön és a Másoló Varázsló | cpp17 | Wrong answer 25/100 | 224ms | 96924 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 999999
int N,M;
int F[1000000];
void add(int i,int x){
for(i++;i<1000000;i+=i&-i){
F[i]+=x;
}
}
void add(int i,int j,int x){
add(i,x);
add(j+1,-x);
}
int get(int i){
int x=0;
for(i++;i;i-=i&-i){
x+=F[i];
}
return x;
}
void sset(int i,int x){
add(i,i,x-get(i));
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>M;
vector<int>v(N+1),w(M),u(N+1);
for(int i=1;i<=N;i++){
cin>>v[i];
}
for(int i=0;i<M;i++){
cin>>w[i];
}
sort(w.begin(),w.end());
for(int i=1;i<=N;i++){
u[i]=upper_bound(w.begin(),w.end(),v[i])-w.begin();
}
int a=0,l=0,h=500000;
add(0,h-1,INF);
h++;
for(int i=1;i<=N;i++){
int aa=INF;
int j=u[i]-1;
if(j>=l){
aa=min(aa,get(h+j));
}
h--;
if(w[l]>v[i-1]&&a<INF){
sset(h+l,get(h+l+1));
}
else{
l++;
}
int ll=l,hh=M;
while(ll<hh){
int mm=(ll+hh)/2;
if(get(h+mm)<=a){
hh=mm;
}
else{
ll=mm+1;
}
}
add(h+l,h+u[i-1]-1,1);
add(h+ll,h+M-1,1);
if(v[i]>v[i-1]){
aa=min(aa,a);
}
a=aa;
}
int ans=a;
for(int i=l;i<M;i++){
ans=min(ans,get(h+i));
}
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2028 KiB | ||||
2 | Wrong answer | 48ms | 7012 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 57ms | 6716 KiB | ||||
4 | Accepted | 57ms | 6712 KiB | ||||
5 | Accepted | 57ms | 6780 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 3ms | 3888 KiB | ||||
7 | Accepted | 3ms | 3852 KiB | ||||
8 | Accepted | 3ms | 4104 KiB | ||||
subtask4 | 0/15 | ||||||
9 | Wrong answer | 3ms | 4476 KiB | ||||
10 | Wrong answer | 3ms | 4548 KiB | ||||
11 | Wrong answer | 3ms | 4756 KiB | ||||
12 | Wrong answer | 3ms | 4892 KiB | ||||
subtask5 | 5/5 | ||||||
13 | Accepted | 6ms | 5508 KiB | ||||
14 | Accepted | 6ms | 5464 KiB | ||||
15 | Accepted | 6ms | 5820 KiB | ||||
subtask6 | 5/5 | ||||||
16 | Accepted | 6ms | 5820 KiB | ||||
17 | Accepted | 6ms | 5608 KiB | ||||
18 | Accepted | 6ms | 5760 KiB | ||||
19 | Accepted | 6ms | 5816 KiB | ||||
subtask7 | 0/10 | ||||||
20 | Wrong answer | 6ms | 5932 KiB | ||||
21 | Wrong answer | 6ms | 5940 KiB | ||||
22 | Accepted | 7ms | 6064 KiB | ||||
23 | Wrong answer | 4ms | 5940 KiB | ||||
24 | Wrong answer | 7ms | 6144 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Accepted | 90ms | 15160 KiB | ||||
26 | Accepted | 90ms | 17128 KiB | ||||
27 | Accepted | 89ms | 19168 KiB | ||||
28 | Accepted | 3ms | 11464 KiB | ||||
29 | Accepted | 105ms | 21188 KiB | ||||
30 | Wrong answer | 86ms | 21804 KiB | ||||
31 | Wrong answer | 85ms | 24456 KiB | ||||
32 | Wrong answer | 85ms | 27072 KiB | ||||
33 | Wrong answer | 89ms | 28908 KiB | ||||
34 | Wrong answer | 87ms | 30976 KiB | ||||
35 | Wrong answer | 90ms | 32828 KiB | ||||
36 | Wrong answer | 83ms | 34036 KiB | ||||
37 | Wrong answer | 85ms | 36700 KiB | ||||
38 | Wrong answer | 90ms | 38456 KiB | ||||
39 | Accepted | 105ms | 40404 KiB | ||||
40 | Accepted | 93ms | 42312 KiB | ||||
41 | Wrong answer | 92ms | 44304 KiB | ||||
42 | Wrong answer | 54ms | 42004 KiB | ||||
43 | Wrong answer | 90ms | 46072 KiB | ||||
44 | Wrong answer | 86ms | 49284 KiB | ||||
45 | Wrong answer | 87ms | 51308 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Wrong answer | 167ms | 62932 KiB | ||||
47 | Wrong answer | 175ms | 67044 KiB | ||||
48 | Wrong answer | 172ms | 69180 KiB | ||||
49 | Accepted | 222ms | 74808 KiB | ||||
50 | Accepted | 224ms | 78572 KiB | ||||
51 | Wrong answer | 224ms | 82484 KiB | ||||
52 | Wrong answer | 163ms | 83328 KiB | ||||
53 | Wrong answer | 182ms | 88300 KiB | ||||
54 | Wrong answer | 184ms | 92768 KiB | ||||
55 | Accepted | 185ms | 96924 KiB |