#include<bits/stdc++.h>
//#define int long long
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
//#define ordered_multiset tree<long long, null_type,less_equal<long long>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long, null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
//st.order_of_key
//st.find_by_order
main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("deleg.in", "r", stdin);
// freopen("deleg.out", "w", stdout);
#endif
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
vector<int> a(n+1);
ordered_set st;
long long s=0;
for(int i=1;i<=n;++i){
cin>>a[i];
s+=st.size()-st.order_of_key(a[i]);
st.insert(a[i]);
}
st.clear();
vector<int> b(m+1),ans;
vector<pair<int,int>> v;
long long sum=0;
for(int i=1;i<=m;++i){
cin>>b[i];
if(i>n){
st.erase(b[i-n]);
sum-=st.order_of_key(b[i-n]);
}
sum+=st.size()-st.order_of_key(b[i]);
st.insert(b[i]);
if(sum==s && i>=n){
bool ok=1;
for(int j=i;j>i-min(n,100);--j){
if(a[st.order_of_key(b[j])+1]!=n-i+j){
ok=0;
break;
}
}
for(int j=i-n+1;j<=min(i-n+100,i);++j){
if(a[st.order_of_key(b[j])+1]!=n-i+j){
ok=0;
break;
}
}
if(ok){
ans.push_back(i-n+1);
}
}
}
cout<<ans.size()<<"\n";
for(int to:ans){
cout<<to<<" ";
}
}
Compilation message (stderr)
mat.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
17 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |