제출 #218200

#제출 시각아이디문제언어결과실행 시간메모리
218200Andrei_CotorMatching (CEOI11_mat)C++11
81 / 100
1267 ms65540 KiB
//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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...