This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//alternativ cu aib determin pozitia relativa a fiecarui element cand compar.
//setu asta-i scammer rau... 105mb 1e6 perechi de valori...
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N[1000005],H[1000005];
int P[1000005];
int Smaller[1000005],Greater[1000005];
int St[1000005],Dr[1000005];
int Poz[1000005];
vector<int> Rez;
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;
Poz[i]=x;
}
for(int i=1; i<=n; i++)
{
St[i]=i-1;
Dr[i]=i+1;
}
for(int i=n; i>=1; i--)
{
int ind=N[i];
Greater[i]=Poz[Dr[ind]];
Smaller[i]=Poz[St[ind]];
//sterg ind
St[Dr[ind]]=St[ind];
Dr[St[ind]]=Dr[ind];
}
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... |