狠狠地切割(Hard Version)
狠狠地切割(Hard Version)
(https://www.luogu.com.cn/problem/P8889)
跟easy版非常像,但是数据太大开标记数组的话会爆所.以得转换一下
开一个map<longlong,int>作为标记就好了
注意在每次循环的时候要更新检索的位置
code
for (int i = 1; i <= n; i++) {
cin >> ve[i];
}
for (int i = 1; i <= m; i++) {
cin >> ve1[i];
mp[ve1[i]]= 1;
}
int count = 0;
for (int i = 1; i <= n;i++) {
if(!mp[ve[i]]){
count++;
while (i <= n && mp[ve[i]]!=1)i++;
}
}
要是标记两次的话会被t(我也不知道为什么)
这是被t的code
for (int i = 1; i <= n; i++) {
cin >> ve[i];
mp[ve[i]] = 1;
}
for (int i = 1; i <= m; i++) {
cin >> ve1[i];
if(mp[ve1[i]] == 1)mp[ve1[i]] = 2;
}
int count = 0;
for (int i = 1; i <= n;i++) {
if(mp[ve[i]]==1){
count++;
while (mp[ve[i]]!=2 && i <= n)i++;
}
}
cout << count;
return 0;
}