이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//alternativ cu aib determin pozitia relativa a fiecarui element cand compar.
#include<iostream>
#include<vector>
#include<set>
using namespace std;
int N[1000005],H[1000005];
int P[1000005];
int Smaller[1000005],Greater[1000005];
vector<int> Rez;
set<pair<int,int> > S;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1; i<=n; i++)
{
int x;
cin>>x;
N[x]=i;
}
for(int i=1; i<=n; i++)
{
set<pair<int,int> >::iterator it=S.upper_bound({N[i],0});
if(it!=S.end())
Greater[i]=(*it).second;
if(it!=S.begin())
{
it--;
Smaller[i]=(*it).second;
}
S.insert({N[i],i});
}
for(int i=1; i<=m; i++)
cin>>H[i];
for(int i=2; i<=n; i++)
{
int k=P[i-1];
while(k!=0)
{
if(Smaller[k+1]!=0 && N[i-k-1+Smaller[k+1]]>N[i])
{
k=P[k];
continue;
}
if(Greater[k+1]!=0 && N[i-k-1+Greater[k+1]]<N[i])
{
k=P[k];
continue;
}
break;
}
P[i]=k+1;
}
int l=1;
for(int i=2; i<=m; i++)
{
while(l!=0)
{
if(Smaller[l+1]!=0 && H[i-l-1+Smaller[l+1]]>H[i])
{
l=P[l];
continue;
}
if(Greater[l+1]!=0 && H[i-l-1+Greater[l+1]]<H[i])
{
l=P[l];
continue;
}
break;
}
l++;
if(l==n)
{
Rez.push_back(i-n+1);
l=P[l];
}
}
cout<<Rez.size()<<"\n";
for(auto el:Rez)
cout<<el<<" ";
cout<<"\n";
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... |