This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
const int N=200005;
int32_t main() {
LCBorz;
int n,m;cin>>n>>m;
vector<int> a1(n),a(n),b(m),ans;
int idx=0;
for(int i=0;i<n;i++){
cin>>a1[i];
}
for(int i=0;i<n;i++){
a[a1[i]-1]=i+1;
}
for(int i=0;i<n;i++){
idx=(a[i]==1?i:idx);
}
for(int j=0;j<m;j++){
cin>>b[j];
}
deque<int> dq;
for(int i=0;i<m;i++){
while(dq.size()&&dq.front()<=i-n){
dq.pop_front();
}
while(dq.size()&&b[dq.back()]>b[i]){
dq.pop_back();
}
dq.push_back(i);
if(i>=n-1&&dq.front()-i+(n-1)==idx){
vector<int> t;
for(int j=0;j<n;j++){
t.push_back(b[i-(n-1)+j]);
}
sort(all(t));
int flag=1;
for(int j=0;j<n;j++){
if(b[i-(n-1)+j]!=t[a[j]-1]){
flag=0;
}
}
if(flag)ans.push_back(i-(n-2));
}
}
cout<<ans.size()<<endl;
for(int j:ans){
cout<<j<<' ';
}
cout<<endl;
return 0;
}
# | 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... |