Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main(){
- ios_base::sync_with_stdio(false);cin.tie(nullptr);
- int m,k,n,s;
- cin>>m>>k>>n>>s;
- int a[m];
- for(int i=0;i<m;i++){
- cin>>a[i];
- }
- int b[s];
- for(int i=0;i<s;i++){
- cin>>b[i];
- }
- int delta = m - n * k;
- map<int,int> good;
- for(int i=0;i<s;i++){
- good[b[i]]++;
- }
- map<int,int> cur;
- for(int i = 0; i < delta + k - 1; i++){
- cur[a[i]]++;
- }
- int curVal = 0;
- for(auto [v, q] : good){
- if(cur[v] >= q){
- curVal++;
- }
- }
- int needSize = good.size();
- vector<int> v;
- for(int i = delta + k -1; i < m ;i++){
- cur[a[i]]++;
- if(cur[a[i]]==good[a[i]]){
- curVal++;
- }
- if(curVal==needSize){
- v.push_back(i - delta - k + 1);
- }
- cur[a[i - delta - k + 1]]--;
- if(cur[a[i - delta - k +1 ]] + 1 == good[a[i -delta - k + 1]]) curVal--;
- }
- for(int i : v){
- if(i%k==0){
- bool del[delta + k] = {false};
- multiset<int> Set;
- for(int j=i;j<delta+k+i;j++){
- Set.insert(a[j]);
- }
- for(auto [v,q] : good){
- while(q--){
- Set.extract(v);
- }
- }
- int curActive = s;
- while(curActive<k){
- Set.extract(Set.begin());
- curActive++;
- }
- for(int j=i;j<delta+k+i;j++){
- if(Set.find(a[j])!=Set.end()){
- del[j-i] = true;
- Set.extract(a[j]);
- }
- }
- vector<int> ans;
- for(int j = i; j<delta + k + i; j++){
- if(del[j-i]){
- ans.push_back(j+1);
- }
- }
- cout<<ans.size()<<endl;
- for(int i : ans){
- cout<<i<<" ";
- }
- return 0;
- }
- }
- cout<<-1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement