100392024-03-25 18:15:03111Növekvő Ödön és a Másoló Varázslócpp17Wrong answer 25/100224ms96924 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2028 KiB
2Wrong answer48ms7012 KiB
subtask25/5
3Accepted57ms6716 KiB
4Accepted57ms6712 KiB
5Accepted57ms6780 KiB
subtask310/10
6Accepted3ms3888 KiB
7Accepted3ms3852 KiB
8Accepted3ms4104 KiB
subtask40/15
9Wrong answer3ms4476 KiB
10Wrong answer3ms4548 KiB
11Wrong answer3ms4756 KiB
12Wrong answer3ms4892 KiB
subtask55/5
13Accepted6ms5508 KiB
14Accepted6ms5464 KiB
15Accepted6ms5820 KiB
subtask65/5
16Accepted6ms5820 KiB
17Accepted6ms5608 KiB
18Accepted6ms5760 KiB
19Accepted6ms5816 KiB
subtask70/10
20Wrong answer6ms5932 KiB
21Wrong answer6ms5940 KiB
22Accepted7ms6064 KiB
23Wrong answer4ms5940 KiB
24Wrong answer7ms6144 KiB
subtask80/25
25Accepted90ms15160 KiB
26Accepted90ms17128 KiB
27Accepted89ms19168 KiB
28Accepted3ms11464 KiB
29Accepted105ms21188 KiB
30Wrong answer86ms21804 KiB
31Wrong answer85ms24456 KiB
32Wrong answer85ms27072 KiB
33Wrong answer89ms28908 KiB
34Wrong answer87ms30976 KiB
35Wrong answer90ms32828 KiB
36Wrong answer83ms34036 KiB
37Wrong answer85ms36700 KiB
38Wrong answer90ms38456 KiB
39Accepted105ms40404 KiB
40Accepted93ms42312 KiB
41Wrong answer92ms44304 KiB
42Wrong answer54ms42004 KiB
43Wrong answer90ms46072 KiB
44Wrong answer86ms49284 KiB
45Wrong answer87ms51308 KiB
subtask90/25
46Wrong answer167ms62932 KiB
47Wrong answer175ms67044 KiB
48Wrong answer172ms69180 KiB
49Accepted222ms74808 KiB
50Accepted224ms78572 KiB
51Wrong answer224ms82484 KiB
52Wrong answer163ms83328 KiB
53Wrong answer182ms88300 KiB
54Wrong answer184ms92768 KiB
55Accepted185ms96924 KiB