161922025-04-14 14:40:04zsomborNövekvő Ödön és a Másoló Varázslócpp17Wrong answer 5/100152ms7276 KiB
// Növekvő Ödön és a Másoló Varázsló.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, m, ans = 1e9;
vector <int> a(5e5, 0);
vector <int> b;
vector <int> dp(5e5, 1e9);
vector <int> f(5e5, 1e9);

int gr(int x) {
	return b.end() - lower_bound(b.begin(), b.end(), x);
}

int pos(int k) {
	return n + m - k - gr(a[k]);
}

void update(int k) {
	int x = pos(k);
	for (int i = x; i < f.size(); i = (i | (i + 1))) f[i] = min(f[i], dp[k]);
}

void query(int k) {
	int x = pos(k) + 1;
	for (int i = x; i >= 0; i = (i & (i + 1)) - 1) dp[k] = min(dp[k], f[i]);
	dp[k]--;
	ans = min(ans, dp[k]);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	b.resize(m);
	for (int& i : b) cin >> i;
	sort(b.begin(), b.end());
	dp[0] = n;
	for (int i = 1; i <= n; i++) {
		if (a[i - 1] < a[i]) dp[i] = dp[i - 1];
		query(i);
		update(i - 1);
	}
	cout << ans << "\n";
	/*for (int i = 0; i <= n; i++) cout << pos(i) << " ";
	cout << "\n";
	for (int i = 0; i <= n; i++) cout << dp[i] << " ";*/
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms6196 KiB
2Wrong answer35ms6452 KiB
subtask20/5
3Accepted52ms6964 KiB
4Accepted52ms7040 KiB
5Wrong answer52ms6964 KiB
subtask30/10
6Wrong answer6ms6196 KiB
7Wrong answer7ms6196 KiB
8Accepted7ms6196 KiB
subtask40/15
9Accepted7ms6196 KiB
10Wrong answer7ms6196 KiB
11Accepted7ms6196 KiB
12Wrong answer6ms6392 KiB
subtask55/5
13Accepted7ms6196 KiB
14Accepted8ms6392 KiB
15Accepted8ms6408 KiB
subtask60/5
16Wrong answer8ms6336 KiB
17Wrong answer8ms6196 KiB
18Wrong answer8ms6196 KiB
19Wrong answer8ms6388 KiB
subtask70/10
20Accepted8ms6336 KiB
21Accepted8ms6088 KiB
22Wrong answer8ms6264 KiB
23Accepted7ms6100 KiB
24Wrong answer8ms6196 KiB
subtask80/25
25Wrong answer59ms6452 KiB
26Accepted59ms6452 KiB
27Accepted57ms6572 KiB
28Accepted4ms6196 KiB
29Wrong answer75ms6708 KiB
30Accepted57ms6452 KiB
31Accepted57ms6584 KiB
32Accepted59ms6452 KiB
33Accepted59ms6452 KiB
34Accepted59ms6452 KiB
35Accepted61ms6452 KiB
36Accepted57ms6452 KiB
37Accepted57ms6452 KiB
38Accepted61ms6452 KiB
39Wrong answer75ms6452 KiB
40Wrong answer61ms6704 KiB
41Accepted61ms6708 KiB
42Accepted37ms6452 KiB
43Accepted57ms6592 KiB
44Accepted57ms6452 KiB
45Accepted59ms6700 KiB
subtask90/25
46Accepted111ms7096 KiB
47Accepted115ms7276 KiB
48Accepted109ms7108 KiB
49Wrong answer152ms7080 KiB
50Wrong answer150ms7080 KiB
51Wrong answer150ms7088 KiB
52Accepted101ms6964 KiB
53Accepted108ms7032 KiB
54Wrong answer116ms6964 KiB
55Wrong answer115ms6964 KiB