이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int cnt=0;
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){
cnt++;
assert(cnt<=m/n+1);
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;
break;
}
}
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... |