제출 #218219

#제출 시각아이디문제언어결과실행 시간메모리
218219Andrei_CotorMatching (CEOI11_mat)C++11
100 / 100
435 ms48076 KiB
//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 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...